Objective-C Is The Language
November 7th, 2011My good friend Brent Simmons invokes a historical email from Linus Torvalds, about his disdain for C++
C++ is a horrible language. It’s made more horrible by the fact that a lot of substandard programmers use it, to the point where it’s much much easier to generate total and utter crap with it.
Brent affirms his support while paying homage to plain-old C:
But I will admit to an enduring love of C. I still think of C not as C but as the language.
I loved C. Emphasis on the past-tense. As object-oriented programming concepts became popular, those of us who were programming in C or similar procedural languages had to find new, object-oriented languages to fulfill our needs. At the time, I chose C++. Or I should say, I had C++ forced upon me. Because C++ popularized the notion of object-oriented programming, it was the only choice presented to many programmers.
Because I ended up at Apple, the time I spent with C++ was thankfully short. They were fortuitously behind the times at the dawn of my career, and wound up taking a different path while my career was ascending.
Objective-C was Apple’s response to object-oriented programming, and continues to be the lingua-franca for programmers on Macs, iPhones and iPads. I loved C. I love C. But it always fell short for me. It lacked something. Objective-C fixed that. I hope I never have to program in C++ again. But tellingly, I also hope I never have to program in C again.
There are lots of great features from Python, Ruby, or JavaScript, that I’d love to see incorporated into Objective-C. By no means is it perfect. But for its elegance, and for the fact that it fulfills many of the requirements of object-oriented programming, while maintaining the familiar simplicity of C, it presently earns the title of the language for me.
[Update Nov 7: I’ve had a lot of reaction to my claim above that Objective-C was “Apple’s response to object-oriented programming.” This makes it sound like Apple invented the language, and they didn’t. But they have done more to popularize and promote it than anybody else. I stand by the meaning of it being “what they bring to the table,” when it comes to object-oriented programming].
Translation: Thanks to Anja Skrba, you can now read this article in Serbo-Croatian.
November 7th, 2011 at 2:57 am
I am still in the honeymoon phase of learning Objective-C (coming from a degree program that focused mainly on Java) and I must say I definitely appreciate it’s elegance. Being able to dip down into C and it’s marriage to the Cocoa frameworks just make it feel “right” for whatever I’m trying to do with it.
A similar approach utilizing Java feels more like using an oar to butter a corn muffin.
November 7th, 2011 at 3:39 am
Objective-C was my first OO language and will always have a special place in my heart. That said, now that I do my day-to-day programming in Ruby, I have grown quite fond it as well. MacRuby seems like a very promising child of the two.
November 7th, 2011 at 4:19 am
I would prefer having something like a Smalltalk compiler that let me use inline C code blocks instead of a C compiler with Smalltalk like extensions such as Objective-C.
November 7th, 2011 at 5:08 am
I too learned C++ in college but it was unwieldy. C was always simpler and more natural. I later moved to Java and eventually found my way to Objective-C.
After 5 years it has become the language I think in.
November 7th, 2011 at 5:14 am
[I can_not_stand: [the nested_bracket: [syntax: sorry]]]
November 7th, 2011 at 5:38 am
@kikito Can you stand LISP? ;-)
November 7th, 2011 at 6:09 am
The square bracket syntax is as useful and/or as elegant as LISP.
An eye sore; taxing on the coder at times. An unnecessary effort that we can do without.
That’s why people wish it to be removed.
AppCode converts dot notation to brackets for instance.
These opinions matter. Elegancy wins. Square notation will go down the history as an unloved child that people had to bare with until it will be fixed.
November 7th, 2011 at 6:56 am
For the record I like LISP
November 7th, 2011 at 7:15 am
@Alexandre Jasmin
http://www.exept.de/en/products/smalltalk-x/stx-overview has what you would like.
November 7th, 2011 at 7:19 am
I am learning Objective C in order to start on my idea for iPad application..
November 7th, 2011 at 8:12 am
While Objective-C is by far my favorite language, I don’t think I will say this is “the language”.
My personal opinion in this matter, is that there is nothing like “the language” and I just use the language that fit my need.
When I’m writing Mac OS X and iOS application, I’m using Objective-C, but I love too fallback to plain C or C++ when I need features they do better than Objective-C (especially when I have to write performance sensitive code).
If I have to write a quick prototype, I don’t hesitate to use scripting language like Python.
November 7th, 2011 at 9:08 am
I understand the dislike of square bracket notation but you do get used to it, and it does allow the clean separation of message-based code and C. The verbosity of Obj-C is one of its strengths — seldom do you see a toolbox call and wonder WTF it is.
The argument for Smalltalk + inline C is interesting, but would lead to far worse performance for not much gain. I’ve never seen an OS or application developed in Smalltalk I’d want to use. You can achieve much the same result by coding in a “safe” language against Cocoa (PyObjC, MacRuby, or or JavaScript, say).
For me, now, “the” language is JavaScript. JavaScript – eval + optional-strong-typing + conventional-object-model and you’ve got me.
November 7th, 2011 at 9:44 am
Just for the record, Objective C was not “Apple”™s response to object-oriented programming” – Objective C was developed several years before NeXT or Apple started using it by Brad Cox and Tom Love. http://en.wikipedia.org/wiki/Objective-C
November 7th, 2011 at 10:45 am
[I too_can_not_stand: [the nested_bracket: [syntax: sorry]]]
I find it practically violent.
…I do the bulk of my programming C# and prefer it in many ways.
November 7th, 2011 at 11:03 am
I too was ‘forced’ to learn C++ (and now Java) in college. Of course, I’m just a student and don’t know as much as any of you guys, but for the last two years I have been learning Ruby, C and Objective-C in my free time and doing things and writing small apps and I must say I adore Ruby for its elegance and complete object-orientedness and I find (pure) C very fun to write mainly because of its simplicity and because of my fascination for the low-level. I find Objective-C also very nice, with advantages of both, though I haven’t used it that much and I prefer it to C++ or Java.
Now macruby sounds interesting, but I’m worried about how long and how much Apple will actually back it up.
November 7th, 2011 at 11:10 am
It’d be cool if Objective-C 3.0 could remove the square brackets and use true Smalltalk-like syntax. F-Script proves it can be done.
If it would help to give the compiler hints, the requirement could change to have just one top-level pair of square brackets enclosing any messaging statement or top-level expression:
foo = [MyGraphPoint pointWithX: xField floatValue y: yField floatValue];
[self graph plotPointAtX: foo x y: foo x];
I might have my precedence rules for Smalltalk syntax mixed up, but it would be something like this, with parens as needed for grouping. The brackets would tell the compiler, “Here comes some Smalltalk.”
Removing the brackets, which some people find ugly, would be consistent with Apple’s trend of making things easier for newcomers to the platform. I suppose there would still be people uncomfortable with Smalltalk syntax.
November 7th, 2011 at 12:57 pm
The interesting parts of ObjC are Smalltalk.
November 7th, 2011 at 3:40 pm
I have trouble taking seriously people who whine about the square brackets.
November 7th, 2011 at 5:50 pm
My first language was hex code, punched directly into memory locations, set the PC to the first one, and start the processor.
Compared to that, C was like magic.
I did twenty years with C++, and, along the way, have learned lots of languages, but the strangest was XSLT.
I now run a shop that does C++ HPC. There’s no other language that comes close, when you want raw performance. You also want good (read: expen$ive) geeks writing it. It’s not a good language for the faint of heart.
I like O-C. I got used to the bracket syntax (from SmallTalk). It’s OK.
A lot of these languages came from architects, trying to force bad programmers to write good code.
Good luck with that…
November 7th, 2011 at 8:52 pm
Eiffel anyone ??
November 8th, 2011 at 10:18 am
If you come from c/c++ maybe Objective-C looks nice. Less so if you’re coming from Java (which makes way more sense) or Ruby (which is the most elegant language).
[note: I don’t consider c-compatibiltiy an asset in any way – I’d be happy if Apple dumped that tomorrow. pointers? really? give me a break]
Criticisms: The brackets are dumb. Pointers are dumb (though I’ve gotten so used to it by now that I don’t even see the ‘*’ in front of everything). The:method:names where you have named parameters (but you can’t omit one, or define defaults) are dumb. The header files are… well OK they’re fine. Manual memory management is dumb – although they now have automatic compile time memory management which looks super interesting. Anyway having to count references is crazy, and if it weren’t for properties I’d probably have given up. Encapsulation is unheard-of. Subclassing and constructors are weird and fiddle-y.
Good things: Categories. Wow. How I love categories. LOVE IT. General object-orientedness, though I dislike the primitives all over the frameworks. Ruby does that right: Everything is an object, and deal with “efficiency” where that sort of thing belongs, in the compiler / interpreter.
And… frameworks. I am truly impressed with the quality of the frameworks for UI stuff and also for core stuff. The frameworks are fantastic. If you’ve ever written a user interface in Java, discovering Apple’s UI frameworks is a relegation. That’s how it’s supposed to work. Yeah!
AppCode, which is a full on IDE vs the glorified text editor that is Xcode 4. Just like Eclipse/IDEA do for Java, AppCode removes a lot of the shortcomings of Objective-C. For example, it generates/synthesizes/deallocs properties with one click. It has refactorings that work well. Etc.
November 8th, 2011 at 10:26 am
The memory management mechanism is a shit. It is based on naming conventions. And with the properties have more turns.
Typification is a mixture of weak and strong, with the type id. If you call a method on this type throws a warning, but if an object is assigned to do an implicit cast (though it throws warnings if you want to assign a protocol implemented!)
It has constructors
Delegates are strongly based on, but no inner classes
No null pointer validation, it simply returns null. Go encountered an error when chained method calls.
It has no namespace, such as packages.
There is no decent bookstores mechanism. In many cases you have to get third-party sources in the application.
Methods have no visibility specifiers. Or are public or are private.
To make private methods to do a trick with a category (or declare them before you call).
There is a protected visibility.
In reality there is no private, because if you invoke a method on the interface is not run it without problems (only gives a compiler warning)
It makes some automatic castings. For example, id to any type. Or a superclass to a subclass (but when the subclass has a protocol throws a warning!)