The Missing Link: From Objective-C To Java

I took a different professional trajectory than most of my peers: I received a degree in mechanical engineering but quickly decided to become a "corporate" developer using Paradox, Delphi, VB, and PL/SQL instead. Although I'd been programming since about age 10 on various pre-PC machines, to get where I am today, I had to slowly work my way down through layers of abstraction and technology on my own without the benefit of a formal computer science education (this has its benefits I suppose, but I can't really recommend it). As a mechanical engineering student a couple of years before the Web was invented (yikes!), my exposure to then-current technology was limited. For a time, various engineering algorithms in FORTRAN running on VAX mainframes were a daily headache (along with a semester's addiction to a MUD), though over time there were increasing uses for Macintosh word-processing and DOS-based MATLAB. In any case, as a result of this history, I'm generally quite interested in programming languages and various technologies outside my daily experience. So, over the weekend, I did some reading about Mac OS X and Cocoa to look at things from another perspective. This led me quickly to Objective-C, Cocoa's language of choice.

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.

Comments:

Sadly, once you dig into it, you'll find that the Cocoa-Java bridge is not, in fact, a very viable option. Why? Take your pick. The most obvious roadblock is the lack of documentation and lack of any known non-trivial example of the bridge in use in a real-world application.

Next up, consider the implementation. My favorite detail is that the Obj-C Cocoa peers in Java rely on finalizers for memory management. Yikes. As you probably know, finalizers are notorious for \*killing\* the performance of generational GC algorithms, which Apple's JVM uses.

Finally, there's the syntax goodness. Whereas Obj-C has all kinds of nice syntax for dynamic method dispatch, Java's reflection, while powerful, is quite verbose, and makes API calls that would be simple in Obj-C quite baroque in Java.

But don't take my word for it; please do take a look yourself and blog your thoughts. I'd love to hear what you think,

Posted by Ben Galbraith on February 07, 2005 at 12:57 PM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

toddfast

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today