Slashdot Mirror


What Did Objective-C Do Wrong?

Dixie_Flatline asks: "Okay, I really don't understand it. I've looked at C++ and C# and I don't understand what ObjC must have done wrong to be losing out to the likes of them. It's got only a few syntax additions to C, but is actually fully object oriented, unlike C++. My only hope for ObjC right now are the GNUstep project (which really isn't high profile enough) and MacOS X (which is fine with me...it's like having my NeXT resurrected). But why hasn't ObjC just caught on on its own?"

2 of 15 comments (clear)

  1. Multiple factors. by rjh · · Score: 4

    Warning: this is the rant of a long-time C++ hacker who hasn't looked at Objective C since he was in college.

    PERFORMANCE

    Objective C was, at the time it was introduced, dog slow. This was due to its "cleaner" design and the way it delayed as much as possible until run-time (both of which are, arguably, the Right Thing). C++, on the other hand, had (and still has) an extremely strict philosophy: you don't pay for what you don't use. If you don't use templates, you don't incur the overhead of them. If you don't use virtual functions, you don't incur the overhead of them. If you don't use <foo>, you don't incur <penalty of foo>.

    CODE REUSE

    Objective C invalidated an awful lot of existing C code. Now, Objective C's defenders will say "... it did no such thing! My program still compiles just fine under C, just as it does under Objective C!" With due respect to them, that's not the point.

    One of C++'s selling points is that you can trivially call C++ from C functions. You can trivially call C from C++ functions. Mix-and-match as much as you like. Heck, you can even write C++ code in C.[*] You can't do that with Objective C. [**]

    Objective C required a vast change in how programs were written (see below). C++ offered a slower, smoother slide into the world of OOP.

    CONSTRAINED PARADIGM

    C++ is, contrary to popular belief, not an object-oriented programming language (OOPL). Objective C is an OOPL. [+] This is another major reason why C++ won out.

    C++ is equally at home with procedural programming, object-oriented programming, generic programming--heck, I've even seen functional programming done in C++ (admittedly, it was a nasty hack, but...). People who loudly trumpet C++'s object-oriented capabilities are, with all due respect, totally missing the point. Personally, I find generic programming to be much more breathtaking than OOP--but if I were to say "C++ is so cool because it's a generic programming language", I'd be missing the point.

    The point is, you can use whatever paradigm you need to get the job done. The unpleasant truth of object-oriented programming is that it is not a panacea; while it does some things really well, there are other things it's lousy at. To really enjoy any benefit from Objective C, you must use an object-oriented solution, regardless of whether or not an object-oriented solution is called for.

    This had the added side effect of making it very marketable to IT departments. Senior executives got to tell their bosses, "Yes, our entire IT department is working in C++ now"... and the techs got to keep on solving problems the same way they always had, and were able to take their time to slowly migrate things to C++. Management was satisfied that "we're using C++"; the techs were satisfied that "well, at least we can keep solving problems in the old C style while we come up to speed".

    With C++, I'm free to use whatever solution I need, whether it's a generic solution, procedural, functional, object-oriented or what-have-you.

    (Let me harp for another moment on generic programming. Damn, is it cool, and I wish more languages supported it. I think generic programming is a seriously overlooked part of programming. End the free advertisement for generic programming.)

    [*] Don't forget, the first C++ compilers were really preprocessors that spat out C sourcecode. Everything you can do in C++, you can do in C... C++ just makes it a lot easier.

    [**] At least, I've never had the patience to do it. I've tried a few times, but it quickly gets nontrivial.

    [+] This is kind-of true. Without fully embracing OOP, you can't use any of Objective C's really cool features--you lose everything which distinguishes it from C. C++ allows you more flexibility in this regard.

  2. Several Problems by Matts · · Score: 5
    First of all, ObjC started out just on NeXT. That made it fairly niche stuff, as you wouldn't find any hobbyists or Universities developing on that platform due to the expense of it. And you didn't find it running on probably 99% of the general computers out there, like Windows machines or other Unix machines.

    The second thing was that despite the ease of development, ObjC was slower than C++ at the time. C++ used a vtable for method dispatch (static dispatch), whereas ObjectiveC was a truly dynamic dispatch system, which while being a better design overall, raised a lot of criticism that meant that a number of people didn't take up the usage of the language because of non-investigative bias (i.e. hearing this in a newsgroup post and basing everything on it). Nowadays ObjC has method dispatch caching code that makes it almost as fast as C++ vtables.

    Another point is the lack of compilers. And not just free compilers either.

    Then there's the runtime library issue: C++ programs link to static programs that don't require anything extra. ObjC programs require a runtime Objective C library (at least they did last time I looked at ObjC). This is offputting if the OS you are shipping for doesn't come with that by default. Note that this is not disastrous so don't flame me on it - its just something I've been told about that people have issues with.

    Finally there's the strange syntax, which doesn't really follow C-like calling convention. It's [Object method:param namedparam2:param2value] is unlike anything anyone has seen in C before, whereas C++ at least was mostly just an extension of the struct idea. Of course you could go on arguing about this forever, such as the fact that Objective C is easier to debug because you can see what are method calls very clearly due to the syntax, and the named params are better. But all that is history now. People don't like to change the way they work, thats why Perl appeals to both C programmers and shell programmers alike - because the cognitive dissonance is low.

    Anyway, I hope that helps.

    For more information on Objective C, apple provides free Objective C documentation (which I believe is based the original NeXT docs) at http://developer.apple.com/techpubs/macosx/System/ Documentation/Developer /Cocoa/ObjectiveC/ObjC.pdf.

    --

    Matt. Want XML + Apache + Stylesheets? Get AxKit.