Objective Cee

Real name Objective-C. It is an object oriented extension to the Cee Language created at a time when Cee Plus Plus was virtually unknown. It is basically C with blocks of Smalltalk Language in it (but no automatic Garbage Collection or blocks in Objective Cee 1.0, but these features have been added by Apple in the 2.0 release of Objective-C and iOS 4 respectively).

Maaster!! You have created ... a monster!!

Yes, Igor! By tr-r-ransplanting Smalltalk's virtual dispatch system into zee skull of my cadaver of zee C language, zee virtual messages shall move zee arms and zee legs of structs and ints! Und zey vill doo our biddings!! Vee vill rool zee wooorld!! Mwha-ha-haha!

Vhat vill you call heem, Maaster??

I vill call him... Id.

Very early implementations earned a reputation for slowness, and initially the only implementations were by Brad Cox.

Steve Jobs and Ne Xt used Objective-C for a computer based on a Mach kernel, 680x0 processor, and Unix, with lessons learned from Mac App/Mac Os, and Smalltalk. It was literally 10 years ahead of its time. [Time has since caught up with it.] Time hasn't entirely caught up. There are still OSs that are as pervasively object oriented (Be Os probably is one) and are as easy to develop for (BeOS is fun to program on, but it still doesn't come close to the old tools from that project). [Next Step is the OS discussed above.]

The Java Language has a run-time model similar to Objective-C (and inspired by Objective-C, according to the creator of Java), but with syntax more like Cee Plus Plus. Brad Cox has a record of this at virtualschool.edu

I thought it was something about message dispatch being more like Smalltalk Language than C++.

Wayne Rosing, James Gosling, and Bill Joy wanted an environment "with the semantics of Smalltalk and the appearance of C". The desire was for "programmer portability"; the perception was (rightly or wrongly) that the infix syntax of Smalltalk was a major impediment to its acceptance by the development community. Smalltalk behavior was always the goal; Cee Plus Plus and Objective Cee were thus viewed as relatively interchangeable options. -- Tom Stambaugh

Next, Inc. took the Objective-C portions of the gnu C compiler (and developed their own run-time library) and polished it over the next 10 years until runtime speed was comparable to (or better than?) modern Smalltalks. They didn't ship the source code to the compiler with Nextstep 10 years ago, but it available on request (on magtapes).

I think it's now available in Apple's Darwin project: developer.apple.com

Richard Stallman mentions a disagreement with Next over the philosophy of copyleft at www.gnu.org

That book defines Objective-C.

Another book: developer.apple.com

[ links updated -- Theerasak Photha ]

Objective-C has two tools, Header Doc and Auto Doc, that are similar to Doxy Gen and Java Doc. Header Doc ships with Ex Code on Panther (Mac Osx 10.3)

Objective-C FAQ: ftp://rtfm.mit.edu/pub/faqs/computer-lang/Objective-C/faq

Objective-C tutorial: otierney.net

Does anyone know of an Objective Cee tutorial that doesn't assume knowledge of C? The apple documentation above reminds me of the Steve Martin bit "How to get a Million Dollars and Never pay Taxes": "First, Get a Million Dollars".

I don't know of one offhand, and since it's not one of the most popular languages in the world, you won't see a bunch of "Learn Objective-C in 20 Minutes For Dummies" books.

However, it is a superset of C, so there isn't a pressing need for such a combination. You can buy any number of C books to learn that part of the language, and then learn the Objective-C extensions to the language, which are very small in number and can literally be learned in an afternoon or less (although, as always, it takes longer to learn effective use of the class library).

The only feature that is actually a change, rather than an addition, is that include files should be imported via #import (which automatically enforces an only-once rule, sidestepping the ugly C hack for doing that). But even there, #include still works, so it's still backward compatible. Objective Cee is, in fact, a strict superset of Cee Language, meaning if you hand a Cee Language source to an Objective Cee compiler, it will compile it perfectly.

I was warned by using #import in gcc compiler. Should I use #include instead?

$ gcc -o hello hello.m -lobjc hello.m:1:2: warning: #import is obsolete, use an #ifndef wrapper in the header file

With the gnu compiler you should use "-Wno-import", in order to not get the warning... If you want one good book to learn Obj-C, buy "Programming in Objective-C", by Stephen Kochan.

[From ObjectiveCeeLanguage]

Extends the syntax of Cee Language to include Smalltalk constructs. An object-oriented C created by Brad Cox. The object-oriented extensions of Objective Cee rely on dynamic pointer-based mechanisms, as opposed to Cee Plus Plus, which gains its behavior through more pervasive modifications of both the syntax and symantics of Cee Language. Many consider Objective Cee to be "more OO" than Cee Plus Plus because of the Smalltalk heritage of Objective Cee. NeXTStep used Obj-C, and so does Apple now- the Cocoa Framework is a port of NeXTStep's APIs.(of course, they're modified in Mac Osx, but... the roots are the same). The Gnu Step project is also porting the Open Step frameworks to various OSes(*nix, Windows, etc.). Their website is www.gnustep.org . [original paragraph reworded to improve historical accuracy -- Tom Stambaugh]

With Objective-C, one gets the low-level capabilities of C as well as the high-level, abstract object-orientedness of Smalltalk. It's far from a compromise, however - the two languages fill in each other's gaps nicely. Objective-C only adds one major syntactical construct - the message send.

[receiver message];

Classes are added as well. These are declared as follows:

@interface SomeClass :

@interface is a preprocessor directive that tells the preprocessor, "a class is being declared. what follows are its instance variables and methods."

@interface seems not to be a preprocessor directive. cpp does nothing on it. [Objective-C was originally implemented as a preprocessor that converted the code to straight C. This is different from the traditional C preprocessor which understands things like #define. Modern Objective-C compilers are true compilers, and you probably couldn't implement the language with a preprocessor anymore.]

{ // begin declaring instance variables int fooInt; id anObject; // id is ' a pointer to an object.' it's a generic type-- any object can be typed as id. } //end declaring instance variables

+(S''''''omeClass *)objectWithFooInt:(int) theInt;

Plus '+' signifies class method. colon ':' signifies an argument. (int) types the argument, and theInt is what the argument is named. a 'method' is a set of instructions, something an object (in this case the class object) knows how to do. This returns an initialized, allocated, and autoreleased instance of SomeClass with a fooInt value of theInt. in order for it to stick around for long, the coder must tell it to do so by sending it a retain message: [theObject retain]; (retain is a method of NSObject that is involved with memory management and paired with a release method.)

-(id) initWithFooInt:(int) theInt object:(id) theObject;

This is an instance method which is roughly analogous to a constructor; the message is sent to an allocated instance, and the init method sets instance variables fooInt and anObject to theInt and theObject, respectively. it returns a fully initialized instance of SomeClass.

@end //end of interface

@implementation S''''''omeClass

In here, the instructions are laid out, and the methods are coded like C functions. the exception is, they can call the superclass' implementation of the method. polymorphism is fully supported in Objective-C.


-- Joe Osborn [but with modifications by Tom Stambaugh]

Attempts to add many missing Smalltalk features, such as blocks, are underway. See Blocks In Objective Cee.

[From ObjectiveClanguage]

An Object Oriented Programming Language which combined the dynamic Object Oriented features of the Smalltalk Language with the speed and low-level programming constructs of Cee Language.

Cee Language and Cee Plus Plus were developed by Bell Labs/AT&T, and Objective Cee was developed by Stepstone. With relatively high license fees, Objective Cee never saw broad use. Its major adopter was NeXT, which based the entire application layer of its OS (Next Step) on Objective Cee. Objective Cee lives on in the same role within Mac Osx.

Cee Plus Plus was made freely available by AT&T as a marketing ploy. It was never in the public domain. UNIX(tm) was quite intentionally a trademark of AT&T and has never been in the public domain. AT&T divested a portion of its resources, including UNIX, to NCR corporation for a short period. Meanwhile, a competing version of UNIX was created at Cal Berkeley (by Bill Joy, among others). For many years, the UNIX world was divided between "UNIX System V" (from AT&T/NCR) and "BSD UNIX", from Berkeley. Since AT&T offered Cee Plus Plus for free, Objective Cee would have been "expensive" at any price. -- Tom Stambaugh

One of the quirkier things about ObjectiveC is its (Smalltalk-esque) syntax. Rather than using C++ (and Java's) dot notation for invoking methods, ObjectiveC uses a square bracket form (this is because a dot signifies membership/ownership - you can send any message to any object in Objective C, so a dot would inevitably be semantically wrong):

result = [objectInstance methodName:param];


result = [objectInstance anotherMethod:param1 with:param2 andWithAnotherParameter:param3];

Another hold-over from its lineage, though this one on the Cee Language side, was the use header files (for better or worse). However, at least one thing was fixed: header files are included via the "#import" directive, which automatically ensures that that file is included exactly once, obviating the conventional kludge in C/C++ to achieve that effect.

In practice, both of these are minor compared to the advantages of the language. The core concept that differentiates Objective Cee from most other compiled languages is its runtime. (The advent of Csharp Language has started to bring the power of this concept more to the fore.) To put it simply, in Objective Cee reflection is the way everything's done. There's no such thing as compile-time binding. In other words, Objective Cee is like an interpreted language in terms of flexibility and power (string-to-method-invocation is a no brainer) while having the speed of a fully compiled language (rather than being compiled only to byte code). (Yes, other O-O languages have some the data portion of a runtime: RTTI (Run Time Type Information) for C++, and reflection accesses this information in Java, but no other compiled, C-based language uses the runtime for all method dispatch.)

A more significant limitation of Objective-C is its lack of namespaces and the issue of name collision. As a result various 2 and 3 letter prefixes on class names are common.

This power is achieved by encoding class information into the object files (in the sense of .o files, aka .dll or .so, also known as "libraries") as strings. Upon application execution this information is loaded into the "runtime": a collection of C data structs and functions that are linked into every Objective Cee executable. When a method is invoked, the instance's isa pointer is de-referenced to access the related runtime structs. The method is looked up BY NAME, first in the class and then in each superclass in order. Once a successful lookup has occurred (or failed to occur) the associated function pointer (or pointer to the error function) is cached so that future invocations are fast (~ 2-3x a simple function call).

ObjectiveC is a hybrid language. Within its O-O side it implements all the features of a dynamic O-O language. It supports single-parent inheritance. The base class of all objects is Object. (Actually the runtime supports multiple-base classes and in Next Step, the base class was NSObject,... details.) Having a runtime means that "new" (and generally computationally expensive) features of other languages (like "dynamic proxy classes in Java) are built-in.

From 1988-1995, the base class for the Next Step App Kit was Object. It had no reference counting; only +alloc, -init, and -free were implemented. NSObject was introduced with the Foundation Kit in Next Step 3.3, but only as part of the optional Enterprise Objects Framework. Thus, -retain and -release were introduced because of EOF's need for reference counting. Eventually, the Open Step specification was written with NSObject as the base class, and the App Kit was rewritten massively to build on the new base class. [Brian Willoughby]

An interesting (and powerful) feature is that each Class is also (a special type of) Object in the runtime. Class methods ain't "static" -- they are just as dynamic as any instance method.

One of the slicker features of Objective-C was the notion of a "category". A category (analogous to an "extension" in Envy/IBM Smalltalk) is any collection of methods (class or instance) that are grouped together and given a a name. In addition to being a useful way of grouping class functionality so that multiple developers could conveniently work on different parts of a class, it allows for the addition of new functionality at any point in the class hierarchy by object consumers (rather than just producers). Say you need every instance of any subclass of the Super Gizmo Widget class that you purchased/found in some code library to be able to perform a "twirlAboutAxis:" method. Well, just add such a method into a category on the Super Gizmo Widget class and voila! In other words its the exact opposite of the notion of a "finalize"d class. The limitation is that since instance VARIABLES, unlike instance and class METHODS affect the amount of space that's allocated for an instance, you can't add variables in a category -- or new instances would become incompatible with existing compiled ones. ''

There are a few tricks to categories. Since the runtime must load the base class definition first, categories get loaded second. Conversely method lookups happen in the reverse order: whatever is loaded last is found first. So.... you can effectively override and replace any method on an class by writing a category method of the same name. This, of course, is generally not advised: though it does provide for a wickedly powerful tool for those terrible times when there are bugs in some otherwise very useful base class and you just wish you could fix the one broken method ... with Objective Cee, you can. [As the IBM Smalltalk community discovered, this can lead to pernicious bugs when multiple extensions/categories attempt to define the same method.]

Another feature of the language was its Dynamic Typing. There has been much discussion over the years as to the desireability of this trait. One of the strongest arguments against dynamic typing was that it decreased the ability to do compile-time checks. Compile-time typing was later added to the language -- but it doesn't affect the runtime. In a way the type specifications in Objective Cee amount to code annotations that are parsed by the compiler and produce warnings (or errors) when there's a type mis-match or when trying to invoke a method that the compiler hasn't been informed of.

More information is at: www.dekorte.com

The original Objective Cee compiler was a Cee Language pre-processor. That was back in the 80s. The current Objective Cee compiler has come a ways since then. It is now (thanks to previous negotiations with NeXT) part of the Gnu Compiler Collection. The runtime has been enhanced to support multi-threading.

Various notable Applications have been written in ObjectiveC:

World Wide Web, the first graphical web browser by Tim Berners Lee

Interface Builder, the first wire-up, no code (and no code gen!) Graphical User Interface designer (about a decade later folks are just beginning to develop this sort of a tool in other languages).

Most Mac Osx applications

Many iOS applications

Ezra Epstein [with modifications by Tom Stambaugh] [Historical note by Brian Willoughby]

What do you mean by "no code and no code gen"?

Interface builder does actually generate code (but you have to force that to occur, and it only generates method stubs). However, wiring together the application via IB does not generate source code per se, it generates object instances and serializes them.

There is also an implementation in Clang (Cee Language Family Front End).

At WWDC 2014, Apple replaced Objective C with Swift Language

See original on c2.com