Will JavaScript replace Objective-C as the primary language of Cocoa?
Reading the announcement of SquirrelFish Extreme it crossed my mind that since Apple seems to be putting a lot of effort into JavaScript performance perhaps there’ s more to it than speeding up Safari. Maybe Apple want to make JavaScript fast enough that it could replace Objective-C in the the majority of desktop Cocoa applications.
I never used the ill fated Java version of Cocoa, but from the bit of exposure I’ve had, JavaScript seems like a much more suitable replacement for Objective-C than Java. In fact, I would say that JavaScript, being prototype based, is quite a bit more flexible than Objective-C (though whether that’s a good thing may be questionable). Presumably Java was originally chosen, despite its static typing, because of its popularity but these days is seems like JavaScript is getting more any more attention as a serious language. I suspect in a few years time, JavaScript will become the most common first programming language for engineers, much the way BASIC used to be, simply because it’s so widely deployed in the web browser platform.
Though Apple must be happy with the Objective-C ecosystem they’ve developed, no one else appears to be moving towards it as a language. When compared to C# as in .Net or the Java-ish platform Google is pushing for Android, Objective-C seems difficult to learn and quite low level, especially without garbage collection as on the iPhone. Fewer and fewer engineers even seem to learn C these days, which will no doubt make Objective-C appear more and more difficult to newcomers over time.
The obvious first objection to using JavaScript in the desktop application scenario would be performance, but with so much effort going into improving it, it seems like it won’t be long before it is at least on par with virtual machine languages like C# and Java. To add a bit more evidence to the pile, Apple is clearly somewhat taken with JavaScript if they’re talking about JavaScript frameworks like SproutCore (which I’m told is very Cocoa-like) at WWDC and there are already bindings available for Dashboard widget development.
Ruby and Python might also be viable options if Apple were to move away from Objective-C, but currently suffer the same performance difficulties, and don’t seem to be getting the same level of performance attention (at least from Apple). Time will no doubt tell, but thinking about it, I can’t see a language which would be more suitable as a replacement for Objective-C than JavaScript.
September 20th, 2008 at 1:27 pm
Javascript may be the language on the web, and really awesome applications are being written in it, but there is no way that Javascript will replace Cocoa. It’s not the right tool to accomplish what Cocoa does.
Javascript is single threaded. Care to write a processing intensive app like iMovie without having access to multiple threads? Even seemingly simple operations like opening a menu while rotating a photo would be impossible, because the process would be blocked from doing anything else in the application while pixels are being schlepped around.
There never was a Java version of Cocoa. There was a Java to Cocoa bridge, which allowed developers to call Cocoa methods from Java code. Java is a statically typed language, while Objective-C is a dynamic language. With those very different philosophies, building an effective language bridge becomes difficult. This is why the new Cocoa to Ruby and Python bridges work better — Ruby and Python are also dynamic languages. Prototype based languages, like Javascript, share some qualities of dynamic languages, but really qualify as a class of their own, making an effective language bridge API difficult to build.
Finally, it’s important to see that Objective C is to Cocoa the same way C# is to .Net — neither language gets you far without the library, which ties you to the OS. Most applications are written for only a single OS, so it makes sense that .Net is used in the majority of new apps — and all of those new apps that use .Net are Windows apps. People *are* moving to Objective C — developers from other platforms who want to start selling software for OS X.
September 20th, 2008 at 8:24 pm
Thanks for your comment.
I hadn’t considered the threading issue - But then, threading is more an issue of the underlying platform. Browsers just happen to have a model where single threading applies, where as most operating systems support threading. There is also already precedent for adding threading to JavaScript in Google Gears, so it doesn’t seem like a show-stopper.
And yes, I mean a bridge rather than the underlying layers of Cocoa being rewritten in JavaScript. There’s no reason to assume that couldn’t be the default though - Big chunks of the underlying Java libraries (and I imagine C#) are actually implemented in C, and accessed through a bridge.
September 21st, 2008 at 12:55 pm
I highly doubt this as well, even if you ignore the API layers that would have to be rewritten, or accessed somehow. It is unlikely a Prototype-based language would replace an Object Oriented language for the majority of development. It would make the management of mid-larger programs more difficult.
Also the speeds improvements javascript is having recently simply reducing the lag of an interpreted language by compiling it just in time, approaching native machine code speed. Objective C is and always was running at native machine code speeds.
Third porting large projects takes a lot of time and money. It is unlikely some Carbon apps (like photoshop) would have made a transfer to Cocoa so soon except Carbon is no longer being actively improved for new functionality (like 64 bit API’s and newer multi processor functionality).
Some other thoughts if they were going to go with a language other than objective c, the most likely would be c++. Also, their really isn’t a huge different in the languages since they are both based on c. The main difference is using the API. It took me all of a day to learn the difference in syntax, though I already had a BS in computer science and a couple years experience in programming. What is a real barrier to writing full applications for apple machines is the same as other GUI interfaces. It takes time to learn the large libraries of code (API’s) to use the OS, a project structure that is unique to each OS, and what each part of the project does & how to modify it to what you want.
September 21st, 2008 at 1:04 pm
Thanks for your comment.
Admittedly managing larger JavaScript projects can be tough - It certainly makes it easy for you to shoot yourself in the foot. Once could say the same thing (to a lesser extent) of any dynamically typed language (i.e. Objective-C) though.
I probably didn’t make it clear, but I’m not really suggesting that projects wold be forced to move to JavaScript, just that it would become an option, and perhaps the primary one over time.
And on C++, it has a fairly radically different object model to Objective-C. Admittedly, they made it (sort of) work with Java which is also statically typed, but the typing and design of the Cocoa API seems much more compatible with the JavaScript way of doing things than the C++ way to me.