Slashdot Mirror


Ask Slashdot: Which Classic OOP Compiled Language: Objective-C Or C++?

Qbertino writes: I've been trying to pick up a classic, object-oriented, compiled language since the early 90s, but have never gotten around to it. C++ was always on my radar, but I'm a little torn to-and-fro with Objective-C. Objective-C is the obvious choice if you also want to make money developing for Mac OS X, but for the stuff I want to do, both languages would suffice on all platforms. I do want to start out on x86 Linux, though, and also use it as my main development platform. Yes, I know quite a few other languages, but I want to get into a widespread compiled language that has good ties into FOSS. Both Objective-C and C++ fit that bill. What do you recommend? How do these two programming languages compare with each other, and how easy is cross-platform development in either? (Primarily GUI-free, "headless" applications.)

24 of 407 comments (clear)

  1. c++? by Rinikusu · · Score: 3, Interesting

    I'd go with C++ as the toolchain is mature and if you want to do any GUI work there's Qt, etc. Obj-C is more limited on Linux, but I"m sure the Windowmaker guys would love to have some more folks on board.

    --
    If you were me, you'd be good lookin'. - six string samurai
    1. Re:c++? by menkhaura · · Score: 5, Informative

      Even for non-GUI work, Qt is a blessing if you want to do cross-platform programming. The library does a lot, ranging from database access to network programming, all in a very well documented and well thought out API.

      Good luck.

      --
      Stupidity is an equal opportunity striker.
      Fellow slashdotter Bill Dog
    2. Re:c++? by Anonymous Coward · · Score: 4, Informative

      Objective-C is an ugly, clunky language, and the only reason Apple uses it is to intentionally make your code incompatible with other platforms.

      Actually, they use it for its dynamic binding and loading, but don't let facts get in the way of your FUD!

    3. Re:c++? by Jeeeb · · Score: 5, Informative

      Objective-C is an ugly, clunky language, and the only reason Apple uses it is to intentionally make your code incompatible with other platforms.

      I'm not a particular fan of Objective-C either but this is just wrong. Apple inherited Objective-C when they bought NextStep and used it as the foundation of OS X. OS-X got its start in life as a partial rewrite of the NS shell and the addition of some compatibility layers (Classic Mac OS, Java, .etc.) to make up for the lack of applications. At this stage, there would have to be really really major benefits to a rewrite to justify the direct cost, not to mention the opportunity cost.

    4. Re:c++? by Greyfox · · Score: 4, Informative
      Yes. Dynamic binding and loading is ugly and clunky.Errors you don't catch at compile time are errors that you have to write tests for. You know who writes tests? No one, that's who! So in practice, errors you don't catch at compile time are errors your users are going to catch. And then you have to debug through an ugly clunky maze of dynamic binding and loading.

      But don't get me wrong. I can be... objective... Ok, look. Back in the day we stood at a crossroads. Do we make our changes to C to make it OO fairly lightweight and mostly retain the C syntax, or do we radically change the entire feel of the language. Objective C went for the lightweight approach. Object instances are essentially just pointers to dynamically allocated memory syntactic sugar for pointers to functions around methods. Very C-like idiom and honestly a pretty elegant method of handling things. If you just want C with objective C is worth looking at. It's one step past maintaining some structs with pointers to functions and maintaining OO and inheritance manually, and that's not necessarily a bad thing.

      C++ took longer to get where it was going, but it essentially set out for the strictness of ADA in a C like language. It's much more touchy about types and is geared toward catching as much as it can at compile time. Before they got the STL and the C++11 changes rolled in, it was really kind of a pain in the ass to use. It's big and clunky, has a lot of rules to memorize and its error messages are hideous. But in the right hands, with the right libraries, it can be incredibly concise, remarkably fast and a ridiculously powerful tool. In my opinion, one worth learning.

      In either case, the first thing you should learn is a unit testing framework for that language. No matter what kind of coding you're doing, there's simply not a good excuse to avoid unit testing any code you're planning to deploy anymore.

      And yeah if you go the C++ route, QT is some mighty tasty kool-aid. Sure you have to run their pre-precompiler on your code and will find it much harder if you want to just hook some random non-QT object you have into your system. Sure they demand that their includes be in a specific place in your code. But it's delicious kool-aid! Go ahead, give it a try! I was just playing around the other day with a QT window into which I'd stuffed a QImage that I had loaded up with some pixels from a GDAL raster driver, and it was less than 500 lines of code (Source code's on github if anyone's interested.) Gotta say that was pretty impressive, though still a fairly trivial example.

      --

      I'm trying to teach myself to set people on fire with my mind... Is it hot in here?

  2. C++ is the only logically option by ameoba · · Score: 5, Informative

    C++ is still very much a living, actively developed language. There's a lot of people using it for modern projects. It's well supported under pretty much all modern operating systems & you have excellent tools available under Linux.

    There's not a lot of reason to pick up Objective C unless you plan on targeting Apple. It's pretty much a dead language everywhere else, outside of a few niche projects.

    --
    my sig's at the bottom of the page.
    1. Re:C++ is the only logically option by antifoidulus · · Score: 3, Insightful

      Which is actually kind of sad, as an object oriented superset of C Objective-C is much much better than C++(for starters it's an actual superset of C, unlike C++). However it never gained any traction outside of the Apple ecosystem.

  3. Java by buchner.johannes · · Score: 3, Funny

    I don't expect any contrary opinions here on /.

    --
    NB: The message above might reflect my opinion right now, but not necessarily tomorrow or next year.
  4. C++, C++, C++ by Anonymous Coward · · Score: 3, Informative

    C++ is darn-near universal. It is everywhere and everyone uses it for everything.

    Objective-C is an alternative language used, supported, and pushed by exactly one vendor. It only even exists because of the hipster mentality to "be different" just for the sake of being different with no real other point.

    I don't see how this can possibly be a difficult decision.

    Learn C++, and if you find yourself needing to dabble in Objective-C for some Apple device, no problem there. Doing the reverse would be more challenging and would limit your skills.

  5. C++14 != C++98 by gentryx · · Score: 3, Interesting

    I wish people would stop treating modern C++ as if time had been standing still in the past decades. Yes, C++ is complex, but also expressive. Modern features (e.g. lambdas+auto+templates) often let you write code which is just as concise as its Ruby counterpart, but much more efficient.

    --
    Computer simulation made easy -- LibGeoDecomp
    1. Re: C++14 != C++98 by lq_x_pl · · Score: 4, Funny

      A coworker of mine refers to perl as a 'write-only' language.

      --
      An internal system operation returned the error "The operation completed successfully.".
  6. Re:Objective C by sg_oneill · · Score: 3, Interesting

    C++ can be clean. The problem is really Macro metaprogramming madness tends to lead to some really strange code and sometimes straight up gibberish. I much prefer Objective C as well, I think its terse, readable and *usually* fairly resistant to a lot of the gunk C++ has accumulated. HOWEVER with that said C++ *can* be well written and clear. Hell even PERL can be. Its just that often it isn't.

    --
    Excuse the Unicode crap in my posts. That's an apostrophe, and slashdot is busted.
  7. Objective-C is a lot of work by OrangeTide · · Score: 4, Informative

    Unless you're using Apple's base libraries. Implementing a new Base Library is hard, I've gotten a tiny subset working on my own to see just what is involved. I wouldn't recommend writing the full thing unless you have a burning desire to do it. Porting GNUstep Base Library to various platforms is possible, and has already been ported pretty widely. You'll have to bundle LGPL libraries with your application if you plan to distribute binaries, depending on your application that can make Obj-C a non-starter.

    I use C everywhere, and never C++. C is not the easiest thing to do, but putting together portable frameworks for C is less work than doing the same for Objective-C. (at least in my personal experience, your mileage may vary). C isn't an object oriented language, in that it doesn't do anything special to make that work. But there are OO toolkits for C, with varying degrees of horribleness. A classic is Xt (X Toolkit) and Xaw(X Athena Widgets), which is not terribly C99 friendly anymore. But it does permit limited object-oriented hierarchies. GObject (GTK+) is another option for C, I'm not a fan of it, but it's not obsolete unlike the Xtk/Athena example I mentioned.

    What confuses me about your question is why are you only asking about C++ or Objective-C? There is Free Pascal (Delphi clone) and D. (D is very good, I highly recommend that over Obj-C). There are probably a lot of other options out there that would suit your initial criteria, especially surprising is you didn't mention Java. It's very good example of OO, perhaps OO taken to the extreme, but it's fairly clean. (Obj-C is a little hacky, but thats it's charm and power)

    --
    “Common sense is not so common.” — Voltaire
  8. C++ is probably a little bit better by Chalnoth · · Score: 4, Informative

    There really isn't all that much difference, so that once you get comfortable with one you should be able to switch to the other without much difficulty if you need to. But I'd lean towards C++ because the tools are more mature.

    Two other tips:

    1. Use Clang (part of LLVM) as your compiler. The error messages are vastly easier to interpret, which should cut down on both learning and development time. Note that Clang supports both Objective C and C++.

    2. If you do go for C++, make sure to start learning on C++11 or C++14. C++11 significantly changes quite a lot about the language, and if you start with older C++ books, you'll have to unlearn a lot of stuff if you want to develop modern C++. C++14 has mostly just minor fixes to C++11.

  9. Why not Pascal? by Megol · · Score: 4, Interesting

    Object Pascal that is. It's available in Free Pascal for a lot of operating systems and is a small and fast development environment.

  10. Who cares by Anonymous Coward · · Score: 4, Insightful

    I don't get the whole debate. Programming is independent of language any good programmer should be able to learn a new language in a few days. In my career I've developed applications in four different assembly languages, java, Pascal, C++, basic, etc. It's just a matter of reviewing the syntax and doing the same things in slightly different ways.

  11. Even Apple is abandoning Objective-C by msobkow · · Score: 4, Informative

    Apple has made it clear their development future lies in Swift, not Objective-C.

    That means you're choosing between a popular, well supported language and a dead end.

    The choice should be obvious.

    --
    I do not fail; I succeed at finding out what does not work.
    1. Re:Even Apple is abandoning Objective-C by maccodemonkey · · Score: 4, Interesting

      Apple has made it clear their development future lies in Swift, not Objective-C.

      That means you're choosing between a popular, well supported language and a dead end.

      The choice should be obvious.

      They've done no such thing. The biggest writer and maintainer of Obj-C code is Apple. They're sitting on a huge source base they'll continue developing on. Please link me to where Apple has said Swift is replacing Obj-C. Because they haven't. And they've said the opposite many times. Everything I've read/heard is that Obj-C will continue to be a first class language on iOS and Mac (with Swift and Obj-C both being considered first class languages.) You can have more than one language on a single platform. Shocking, I know.

      Not to mention, for such a dead end, Apple's still writing a lot of new Obj-C. The iWatch OS (what runs on the watch itself) is Obj-C. Apple has not shipped a single API on Mac or iOS written in Swift. Not one. So it makes zero sense that Apple would consider Obj-C a dead language, and yet continue to write source they'll have to maintain for years in it. And if you think Apple is going to rewrite the millions of lines of Obj-C in Mac OS X and iOS in Swift, you really don't understand software engineering very well.

      Another problem is that Swift is missing basic language features. Obj-C can link to C++ code. Swift? Nope. That alone means Swift can't replace Obj-C code. Everyone has C++ code they need to link to. Apple has C++ they need to link to in their own APIs. So does Adobe. Microsoft. And they'll probably fix it in the future. But you can't even approach suggesting Swift is going to replace Obj-C with a straight face until that is fixed.

      Now look, I'm not trying to argue against Swift here. It's a valuable language to use and learn. This isn't a desperate "Obj-C forever!" post. But if you think Obj-C is going anywhere in the next decade or two... It can't. Apple will continue upgrading it, and continue supporting it, or else they're going to end up putting themselves in a corner where they can't even maintain their own software. That's not opinion, that's realism. It's knowing when a tool is right for a problem. And we're nowhere near Swift even being able to entirely replace Obj-C in usage.

      Heck, the last Xcode beta even shipped with some upgrades to Obj-C. So I don't even need to argue that point. It's not a question of if Apple will keep advancing Obj-C. They are.

    2. Re:Even Apple is abandoning Objective-C by maccodemonkey · · Score: 3

      Of course Apple hasn't said Objective-C is a dead end. There would be a revolt and a mass fleeing from the platform if they did that.

      ...from their own developers? Again, out of the whole community, they have the largest Obj-C source base. If they abandon Obj-C within the next 10 years, they won't be able to ship anything. And it's going to take at least a decade to rewrite everything, if that was even their goal. During which time they ship no features. Apple can't abandon Obj-C because they need to use Obj-C. If they abandon Obj-C, they abandon Mac OS X and iOS. And they will be done in the market. And given that new API is still written in Obj-C, that's a process they haven't even started yet. In April they're shipping a brand new hardware platform that still runs on Obj-C.

      For a past data point, Microsoft said with Vista they were going to rewrite Windows in C#. How did that go? Replacing an entire language is simply not realistic. If you're an engineer, you should know that.

      Furthermore, once you're talking about the pain and suffering in moving everything to Swift, maintaining Obj-C looks like a far easier and more desirable costume. And that's what Apple is doing.

      But they sure as hell aren't encouraging people to stay on Objective-C instead of moving to Swift.

      I've talked with engineers on the Swift team who've said that's not the intention (and are wondering why the public thinks that). But please. Do go on.

      I've read several articles and summaries (including on Slashdot) that have made it clear Apple wants people to use Swift.

      "I've read articles from other people who think they know what they are talking about, and they wrote something that they think is right. Look at me! I'm such an expert!"

      Oh, wait. Never mind. Apple person. You don't deal with the same reality as the rest of the world.

      I... deal with the realities on the Apple platform?

  12. Re: Classic? by Em+Adespoton · · Score: 3, Insightful

    Indeed -- learn LISP. Lambda variables, recursion, all atoms being true objects. Then you can redefine the language to pretend to be any of the other HLLs out there.

    Problem is, all the lessons that were learned with LISP have since been forgotten and are doomed to be made again and again.

  13. C++ important on Apple too by perpenso · · Score: 3, Informative

    There's not a lot of reason to pick up Objective C unless you plan on targeting Apple.

    C++ is also important when targeting Apple. Objective-C is the language of the Cocoa API (Mac OS X and iOS), however there is no need to use it beyond code that makes Cocoa based system calls. And getting C++ and Objective-C code to call each other is trivial.

    Personally I recommend separating UI and platform (OS) specific code from an app's core functionality and implementing the UI/platform-specific code in whatever the native language for the platform is and implementing the core code in C/C++. This leaves the core code portable, ready to target other platforms. I have iOS apps where the core code can be compiled in a console Linux environment and exercised by various scripts (regression testing) and in a random manner (fuzzing).

  14. I'd go for C by Zobeid · · Score: 4, Interesting

    Yes... You can do OOP in C. With todays toolchains, libraries and techniques, C is more viable than a lot of people give credit for.

    I personally have always disliked C++, and I know I'm not the only one. I've been OK with Obj-C, but... It is a bit eccentric, and it's probably on the way out with Apple now promoting Swift.

    C, on the other hand, is eternal and evergreen.

  15. Sigh by Cafe+Alpha · · Score: 3, Interesting

    I'm not happy with any language that's available, but that's because I have interests in hard to program stuff.

    I have lots and lots of experience with C++, but I wouldn't recommend it, except as a form of torture. Java too, is gets in your way far too often, though it's better than C++.

    To me, objects are a way of organizing APIs, so I DO like OO...

    What to write it in depends on what features you need. Do you need it to be fast? How fast? Do you need to take advantage of multiple processors? Do you need to share data between them?

    Is programmer time more important than running speed?

    Is reliability more important than programming time?

    One system I'm enjoying these days, though it's far from perfect is Lua, through the amazingly good trace compiler/jit Luajit.
    It is every inefficient in terms of memory. It doesn't support multiple threads. It doesn't even have standard object system, though it's not hard to implement a prototype based one in it... But it's kind of like programming in Self or Ruby with the complexity knob turned all the way down.

    It also has the advantage of running on everything. There's even an ARM version of the JIT.

    If you don't need the speed, Python doesn't look too bad and has lots of libraries.

    If you need something that can be data-center-sized then find a .net language or java... There's a lot of choices under .net and it probably scales the best. Depending on what I was trying to do, I might use F# or ClojureCLR or IronPython...

    The best OO language that time forgot is Dylan. I'm disappointed that Apple never really finished developing it.

  16. The Rust Language by Trevelyan · · Score: 4, Interesting

    I have been mulling similar question for myself for some time. i.e. where should I spend my limited hobby time: learning Obj-C or C++?

    In the last few months Rust has caught my attention. Even then it's not yet at verstion 1 (at time of writing its at alpha-1), I really like the concept and what they are try to achieve with the language.

    My comment will probably be burried, but if you do read it, spend a few minutes wondering around their web site. For exmaple their 30 minute introduction to Rust.