The Missing Link: From Objective-C To Java
By toddfast on Feb 07, 2005
In the past, I'd skimmed information on Objective-C, but at the time its similarity to Java escaped me. I'd also previously studied Smalltalk and saw the similarities to Java there, but it wasn't until I read Apple's Objective-C description that I realized that much of the Smalltalk I saw in Java was filtered through Objective-C and OpenStep instead (of which the latter, not coincidentally, my employer was a big part). That Objective-C was an inspiration for Java isn't exactly a secret, yet no one seems to ever mention it, even here at Sun. What I was most surprised by, however, was the sheer level of similarity between the two languages.
Objective-C is so similar to Java that it's a fairly trivial matter to adjust one's Java mindset to it. Many of the things I love about Java are present in Objective-C. For example, Objective-C encourages interface-based development using what it calls protocols. Objective-C also has a strong runtime component, which normalizes its usage across platforms and offers a very high level of built-in capability. Objective-C even has a couple of features I wish were carried over into Java, like categories. (Poor choice of name but oh, how I've wished for such a feature...) There are some significant differences too, like the Smalltalk-inspired syntax addition to C and the fact that message selectors (method names) exist in a global namespace without regard to number or type of message parameters (this is similar to XML without namespaces, which was a problem when it was initially released). The lack of garbage collection is also a major difference.
When reading the Objective-C language description, it's easy to see how certain features were streamlined to create their Java counterparts. For example, it's obvious that Objective-C's use for the
id pseudo-type apart from the
NSObject formal type was obviated in Java by eliminating the C legacy. One day I'll have to ask James what his perspective is on the amount that Objective-C influenced Java. To me, however, although I know it wasn't the only influence, when reading about Objective-C, it's almost impossible not to feel that Java evolved as a network-aware, small-footprint alternative. There certainly was, and still is, a place for Java as a distinct language and platform, but in some ways it's too bad Objective-C didn't go further. There are surely many reasons for this, but I credit Objective-C's legacy as one stumbling block. Its C and NeXTSTEP origins introduced cruft that was nicely eliminated in Java, with the result being a far more consistent and friendly language--at least until generics were added. <grin> (Don't get me wrong, I love the support for generics introduced in JDK 1.5, but it doesn't do anything to make the Java language easier to read or understand.)
Although nothing will keep me from Java, it'd be nice to jump over into Objective-C once in awhile, if for no other reason than as a change of pace. But, there are a couple of hurdles. First, there isn't a good implementation of OpenStep that is sufficiently cross-platform. This is one of the things I love about Java, and although GNUstep is attempting to provide a portable OpenStep implementation, they're falling short for at least one major platform, and in particular their AppKit implementation is (still) lame. Second, Apple has extended Cocoa nee OpenStep in ways that are very attractive, but again, unavailable anwhere but on the Mac platform (as intended I'm sure). Finally, there are no good-but-inexpensive tools for Objective-C except Xcode and Interface Builder on the Mac; as nice as these tools are, in most ways they aren't really up to the level of capability of a modern Java IDE.
Even though it doesn't seem likely that I'll be writing Objective-C code any time soon (particularly since Cocoa supports the Java language nearly as well), learning about it and its history has been an eye-opening journey, and superb insight into the history of the programming language I use daily. Hats off to Apple for keeping Objective-C not just alive, but vibrant, and to the innovations in language and tools from which we unwittingly benefit today because of it.