Objective-C and the Web

Objective-C is a programming language defined by adding an object oriented layer on top of C, using Smalltalk semantics. The Objective-C language began life as the Object Oriented Pre-Compiler. This was a simple preprocessor that took Smalltalk-like constructs and translated them into pure C code. Since C has no native support for dynamic dispatch, the pre-compiler used a separate library to handle dynamic lookup of methods. This evolved into the Objective-C runtime library.

The runtime library is responsible for implementing the aspects of Objective-C that do not map trivially on to C constructs. Methods in Objective-C are translated to C functions, but the static lookup mechanism used for calling C functions is not applicable to the Smalltalk object model and so a dynamic lookup mechanism is implemented in the runtime. The runtime also defines structures to be used for implementing classes which store the metadata needed for introspection on method and instance variable names and types.

Objective-C was first widely released to the public by Stepstone, a company founded by Brad Cox, the language’s designer, and Tom Love. The company sold an Objective-C compiler and a set of libraries. In 1988, Steve Jobs’ second computer company, NeXT, bought the rights to Objective-C from StepStone and became the main distributor of Objective-C products.

Objective-C was used in NeXT’s operating system, NeXTSTEP in a number of places. Device drivers were written in Objective-C by subclassing generic devices and the entire GUI framework was written in the language. The NeXT Interface Builder is generally regarded as being the first Rapid Application Development (RAD) tool. It produced bundles called nibs which contained serialised object graphs. These typically contained the view and controller objects for a window and were loaded and connected to model objects at runtime. The framework made heavy use of the dynamic features of Objective-C. For example, a common pattern was to provide a delegate to view objects. This would implement some of a set of defined methods and the view would query which it did implement at runtime. A similar pattern is used in Java, however since this language lacks the dynamic capabilities of Objective-C the delegate is required to implement all of the methods, even if the implementation does nothing.

Although NeXT’s development tools were popular with those who used them, the high price of the machines ($10,000 for the early models) kept the number of users small. One of the best known was Tim Berners-Lee, working at CERN. Tim used it to write WorldWideWeb, the first web browser. He later claimed that he would not have been able to do so without the ease of programming provided by Objective-C and specifically NeXT’s AppKit framework. Many aspects of AppKit can be seen in the original implementation of the web. The original tags supported by HTML correspond directly to the attributes recognised by the NSAttributedString object used to represent rich text.

Subsequent web browsers were written in more primitive languages, typically C, and it wasn’t until 1996 that Objective-C appeared on the web scene again. In this instance it was as the core language for WebObjects, the first web application development environment, again produced by NeXT. This was used for many of the early eCommerce sites on the emerging web, as well as others such as the BBC News site and Disney’s online presence.

WebObjects included a companion library, the Enterprise Objects Framework. This was released two years prior to WebObjects, but found significant use when developing web applications. It used many of the dynamic features of Objective-C to implement object-relational mappings, allowing persistent storage of objects in a relational database. Something similar is found in most web application frameworks today.

The most lasting impact on the web can be seen from the impact of Objective-C in the development of Java. Patrick Naughton, one of the two main developers of Java, had been offered a job at NeXT prior to beginning work on Java and ‘thought Objective-C was the coolest thing since sliced bread, and…hated C++.’ Java inherits many attributes from Objective-C, including single inheritance, dynamic binding, dynamic loading, classes as objects, formal interfaces (protocols in Objective-C) and primitive (non-object) types. It adds syntax more familiar to C++ users and a more static type system on top of these.

David Chisnall

HoCC Facebook   HoCC Twitter  HoCC Flikr  HoCC Instagram