Sunday, September 28, 2003

Objective-C

Objective-C has been getting attention in the past few years because the Cocoa application environment on Mac OS X is written in it. Cocoa is the descendant of the NeXTStep AppKit environment.

The Objective-C language was developed by PPI in the 1980s. It added Smalltalk-like object-oriented extensions to ANSI C -- a more conservative approach than C++. Objective-C has full metaclasses like Smalltalk and all method invocations are dynamic. The PPI compiler generated ANSI C and included a small runtime to do method dispatching. NeXT licensed the language from PPI and extended GCC to support Objective-C natively. In 1993, NeXT got out of the hardware business and NeXTStep morphed into OpenStep which was supported on a variety of different platforms including Solaris. In 1997, Apple acquired NeXT and the NeXT AppKit was transformed into Cocoa.

But what's cool about Objective-C? The main distinction is that, unlike C++, types are preserved at runtime and method calls use dynamic binding. The Cocoa runtime needs this type of dynamism to work. Also, Objective-C, like Java, has a single-inheritance hierarchy but supports a mechanism called protocols which allow classes to define the interfaces that they support. It's not a big surprise that Cocoa supports both Objective-C and Java as development languages. In fact, the folks at Apple pushed for Java to get type introspection features like those supported in Objective-C in order for Java to be a useful language for developing Cocoa applications.

The Objective-C language is "good enough" for building dynamic applications. But if that was all that was there, it would have remained an intellectual curiosity. What really makes the language useful is the Cocoa environment itself. The NeXTStep AppKit heritage comes through (note that most of the class names use the prefix "NS" for NextStep). The NeXTStep AppKit was the nicest GUI application framework I've used. It did a great job of hiding complexity and was a natural "fit" for the language. Kudos to Apple for recognizing the value of this technology and keeping the AppKit and Objective-C alive.