Objective-C's niche: why it survives in a world of alternatives
cocoawithlove.com
cocoawithlove.com
I've done C, Assembler, C++ and even python on some embedded devices, as well as the occasional javascript or shell scripts running the show.
Objective C, hands down, is the least hellish language I've EVER done embedded development in. Would I take a python runtime on the iPhone? In a heartbeat. Barring that am I okay with Objective C: Oh hell yes.
It has all the access you may want to C (libraries, certain operations), along with a bolted on smalltalkesque object system that is not overly templated (like java) or overly fiddly and easy to break (like C++) or just plain added on poorly (like lisp).
http://en.wikipedia.org/wiki/Multiple_dispatch http://c2.com/cgi/wiki?MultipleDispatch
I think Apple have found their middle ground with Objective-C - you can really separate the designer/programmer jobs - one creating the Interface, the other programming it.
With Visual Studio, as soon as you double click on the button you are in the code. Some people (me) prefer that, because I'm in a position where I have to design/code myself most of the time, and it seems easier, but over the time, it looks like that's the only easy thing, as soon as your interface grows more complex, then it seems easier to describe most of the connections in IB, rather than your code.
Internally, I've heard Apple uses WebObjects 4.5 for their stores, mobileme, and other web projects.
That's not very accurate. Apple has gone out of their way more so than other companies in giving you options. Apple has always provided the Java bridge for their entire Cocoa API which exposed all of its functionality to the JVM. Apple also ships Python and Ruby bindings and provides documentation and sample code on how to use them.
I have limited experience with all those bindings, but I choose to use Obj-C. In my humble opinion, it's an excellently-designed language that mixes low and high level concepts with great success.
MacRuby is a different beast. It compiles with LLVM, is not bridged, and therefore works directly with Obj-C/Cocoa.
(Though, honestly, the bridged languages are really pretty good, too. Obj-C bridging is good in general. MacRuby is just sensational.)
First look at .NET... there are a lot of .NET developers who think of .NET and C# development as the same... but there are also .NET developers using Ruby, VB#, F#, C++ .NET, and a growing number of scripting languages.
What I've seen of the Cocoa environment isn't Apple restricting developers from using languages other than Objective-C, but rather that Apple is putting its own efforts into Objective-C.
I would agree that Apple seems to be making Java hard to choose for programming the mac lately, but I'd call that progress, and therefore a positive, not a negative ;)
It is interesting that the drop in love for Java occurred around the same time that Carbon was shown the door.
:D
It's no loss... it's just Java. Old... creaky... and why are we still using it again? (Oh, right -- for the progress-averse developers.)
(Obj-C is basically Smalltalk on top of C with a rocking API).
I think delegation is one of the least understood, but most powerful techniques in programming. Being able to inject functionality into another routing based on context allows for reusable work-flow while injected context specific work-flow into that routine, but still allowing that context specific work-flow to have access to encapsulated scope outside of the routine.
This is extremely powerful flexibility, that allows a developer to accomplish developing more functionality with less lines of code.
Agreed. Which ObjC doesn't entirely do; SELs and IMPs are primitive types rather than objects, which is annoying.
I up-voted you even though I was unable to parse this sentence.
I hope that helps, if it is just a convoluted, then I am sorry. Delegates are a pretty abstract subject and I may not be the best at explaining them.
Looked at from the outside, the language oddities (a static, low-level language like C with a very Smalltalk-like flexible runtime system plus the minimum syntax for Smalltalk-style message invocation) are quite off-putting.
It's not until you get inside and really use the system that you can appreciate how well it works.
So people usually just "stay away" unless they really want to get into that particular ecosystem for other reasons (now it's market size for the iPhone; before, it was the cleaner & more compelling Mac OS software niche).
Again, it's not any one particular feature (though most of the individual features are enablers, and can't be dropped), but the overall gestalt that is so (er, can't use "synergistic", I've already used "compelling", how about) coherent.
Cocoa (Foundation and AppKit), and now CocoaTouch, are exceedingly well-crafted, powerful, dynamic-language frameworks that have evolved organically for over 20 years, starting from the NeXT days.
The secret star behind this secret weapon is Ali Ozer, who's had a strong hand on the frameworks' tiller since the beginning, and who's still there.
So, just as Steve Jobs has a singular vision which keeps their hardware efforts focussed, Ali (& his crew, now with a lot of momentum and shared "taste" after all this time) have the same focus at the software framework level.
Swapping out an architecture is way easier than rewriting hundreds of thousands (millions?) of lines of code. Orders of magnitude easier if there is any abstraction at all.
They avoid changing because the perceived benefits are smaller than the costs, which include large switching costs.
We're working on middle-size end user software and we have millions of C++ lines of code. So I can only imagine how many lines of code Apple has riding on Objective-C.
All that said, I wouldn't switch to using any other language with Cocoa because the APIs are natural to Objective-C and they feel quite clunky when used in another language. MacRuby, and particularly HotCocoa, are interesting, but again, there's a re-learning curve involved.
notificationCenter.addObserver_selector_name_object_(
notificationHandler,
"handleMountNotification:",
NSWorkspaceDidMountNotification,
None)
To make it work with some other language (say, C#/C++/Ruby/Brainfuck/Python or whatever) would basically be a complete redesign of the framework, which in turn would basically be a complete redesign of OS X.. And why? Objective C is a perfectly decent language.. I'm not sure anyone would be using it where it not for Carbon/Cocoa, but it's not a bad language at all notificationCenter.addObserver(notificationHandler,
selector:"handleMoundNotification",
name:NSWorkspaceDidMountNotification,
object:nil) notificationCenter addObserver:notificationHandler
selector:#handleMountNotification:
name:NSWorkspaceDidMountNotification
object:nilAnd, it looks like MacRuby is going to be the high-level alternative to Objective-C, with no bridging required.
In a language like Java, declarative application of AOP constructs (such as that of AspectJ) give you all the benefits OP cites for dynamic dispatch, with the further benefits of (a) being still able to reap the benefits of efficient look-up and optimization, and, (b) using declarative programming (which allows for clean decoupling and thus even greater reuse).
Objective-C lives because (as pointed out in another comment) your Mac OS programming life is much more difficult if you choose not to use it.
Does it help you when using someone else's framework that you didn't write and can't control? That being the key benefit that he started with then repeated over and over again.
As a concrete example, can you walk me through how you can take a function that expects to receive objects of a specific class, and instead give them objects of another class? In particular imagine that you are implementing something like NSProxy, and are replacing objects that had lived locally with distributed objects that now exist on a different machine that you access with remote code calls.
The objects have to be usable within a framework that is expecting the original kind of object, and you do not have access to source code or the ability to recompile.
Thanks.
The gist: byte codes are transformed ("weaved") on load. Its irrelevant whether you have the source or not.
http://my.safaribooksonline.com/0596006543/aspectjckbk-CHP-1...
In particular I am now convinced that it can do things that I had not previously realized were possible.
Anyway, the point that I was making is that virtual method dispatch coupled with virtual machines afford the possibility of models of indirection that are more efficient, more expressive, and formally declarable.
As it turns out, that didn't happen - and not because Apple didn't try pushing Java as a Cocoa development language. What happened was users pushed back on slow launching, memory hungry Cocoa-Java apps.
So another reason for Objective-C's success is that yes, it does all the things the original article states, but it also does them in an Ahead-Of-Time compiled, non-Virtual-Machine language - and that combination is pretty unique.
My suspicion is that Obj-C's unique combination of features plays a large part in NeXT/Apple's success in producing a set of frameworks that are high-level enough to allow for rapid development, but are also able to create responsive applications on the desktop AND be able to scale down to mobile devices.
This does not get nearly enough attention when people think about the successes Apple has had over Microsoft since OS X. The sweet spot of a fast, compiled, dynamic language and tools built to leverage those strengths gives Apple a lot of flexibility and productivity in design and implementation, from the OS level to the GUI tool kit level. I think that where Microsoft increasingly found themselves pushing a ball of mud uphill with the Windows code base, Apple was able to do a lot of clever things with their software stack without changing the underlying design and architecture. Like porting their PC OS to a cell phone and allowing their developers to leverage much of their existing skills to make apps for it.
During Jobs' Nexodus, the NextStep environment became the main product because it was such a productive way to build software. With the return to Apple, it stopped being the product and started becoming a competitive advantage.