objective-c
objective-c  
 home  reference  links  credits
 language comparisons

  objective-c smalltalk-80 c++ eiffel
typing dynamic dynamic static static
dynamic binding explicit implicit virtual YES
runtime access to method names YES YES NO NO
runtime accessto class names YES YES NO NO
runtime access to instance variable names YES YES NO NO
forwarding YES YES NO NO
metaclasses YES YES NO NO
inheritance single single multiple multiple
instantiation explicit explicit new create
access to supermethod super super :: renaming
root class Object Object multiple multiple
reciever name self self this current
private data YES YES YES YES
private methods NO NO YES YES
class variables NO YES YES NO
garbage collection NO* YES NO YES
classes are 1st class objects NO YES NO NO


 smalltalk and objective-c

What exactly is it that makes Objective-C have `classes similar to Smalltalk', and what are the resulting capabilities of Objective-C?

Objective-C is as close to Smalltalk as a compiled language allows. The following is a list of the features `taken' from Smalltalk:

compiling

Objective-C is compiled ---Smalltalk is only partially compiled. The current Objective-C implementations are all much faster than any Smalltalk. For example ParcPlace Smalltalk-80/4 is at least 3 times slower than both the GNU and NeXT Objective-C's. (This was measured using the Self/Smalltalk benchmark suite )

typing

Objective-C does hybrid typing : one can choose to represent a string as a `char *' or as an object, whereas in Smalltalk, everything is an object. This is a reason for Objective-C being faster. On the other hand, if every bit of information in an Objective-C program would be represented by an object, the program would probably run at a speed comparable to Smalltalk and it would suffer from not having optimizations performed on the basic classes, like Smalltalk can do.

messages

You may add or delete methods and classes at runtime. (On GNU and NeXT one can load new classes and categories. On Stepstone, which lacks categories, the only way to add methods is to load a subclass which then does a ` +poseAs: ' of the class to have methods added. This is less flexible, but it sort-of does the trick of just adding methods.)

Much of the syntax, i.e. Smalltalk uses method names like ` a:method:name:', as does Objective-C. In Objective-C, the message sending construct is enclosed in square brackets, like this: ` [anObject aMessage: arg]' whereas Smalltalk uses something like ` anObject aMessage: arg'.

The basic class hierarchy, that is, having class `Object' in the very top, and letting most other classes inherit from it.

  • Most method names in class object is the same. E.g. `respondsTo:'. What is called `doesNotUnderstand:' in Smalltalk is called `doesNotRecognize:' in Objective-C.
  • forwarding

    Smalltalk normally uses `doesNotUnderstand:' to implement forwarding, delegation, proxies etc. In Objective-C, these tasks are different: forwarding/delegation: `forward::' can be overridden to implement forwarding. On the NeXT, `forward::' is even used when passing to super.

    remote objects

    Proxies: (Next) An instance of the NXProxy class forwards all methods and their arguments to the remote object via Mach messages.

    classes

    Objective-C has meta classes mostly like Smalltalk but does not have class variables like Smalltalk(pool variables and globals are easily emulated via static variables)




     c++ and objective-c

    dynamic vs. static

    C++ follows the Simula 67 school of OO programming, where Objective-C follows the Smalltalk school.

    In C++ the static type of an object determine whether you can send it a message, in Objective-C the dynamic type determines it. The Simula 67 school is safer, in that more errors are detected at compile time. The Smalltalk school is more flexible, as some valid programs will execute correctly in Smalltalk, where they would be rejected by Simula 67.

    Stepstone's Objective-C allows you to chose between the dynamic and static binding, GNU and NeXT do not. ANSI C++ allows you to use dynamic binding, but discourages you from doing so.

    In many ways, the difference between C++ and Objective-C is more a question of mindset than technical barriers. Are you willing to offer some flexibility for some safety? Advocates for the Simula 67 school claims that a well designed program doesn't need the extra flexibility (a lie), while advocates for the Smalltalk school claims that the errors are no problem in practice (another lie).

    operator overloading

    Whether the usefullness of operator overloading is greater than it's problems is not agreed upon. But it is clear that it violates encapsulation and is a not an OO related feature.

    multiple inheritance

    The merits of multiple inheritance are also debatable. In any case, There are several ways to use similiar mechanisms in Objective-C(such as delegation via message forwarding).

    syntax and semantics

    Objective-C is C plus just a small number of new features all of which are related to adding OO features.