I was re-reading The Design and Evolution of C++, and was struck by a new thought in the C++ vs. Objective-C discussion that rages through my mind from time to time. I like and use both languages, but they’re similar enough in goal and function that it seems a shame that one language can’t suffice1. Usually, I compare the two languages in terms of differences like their (very different) object models and their (very different) syntax. But today I had a new idea:
I’ve noticed a commonality in motion pictures that are based on novels. In the novel, you will often find a scene that goes something like this: “The obvious thing to do here is X. But because of A, B and C, we have to do Y instead, which will take an extra 150 pages.” In the movie version, they usually just do X in the first place, with no mention made of A, B, C or Y. It’s a convenient way of cutting the plot down to size.
In sections 3.9 and 10.2 of D&E, Stroustrup explains that he wanted C++ to allow “separate specification of allocation and initialization.” But he didn’t want to actually separate allocation and initialization, because he wanted the
new operator to ensure that objects were always properly constructed. He also wanted per-class allocation, but assignment to
this was considered too ugly. So C++ has
operator new(). Actually, it has several different operators
How does this work in Objective-C2? Well, allocation (
alloc) and initialization (
init) are separate, and you do per-class allocation by assigning to
self. And The Objective-C Programming Language is 800 pages shorter than the The C++ Programming Language. Movie-sized.
|1||Some people would probably say that it does, and that it’s called Java.|
|2||By Objective-C, by the way, I mean the NeXT, Apple and GNU implementations. If your name is David Stes, pretend I’m talking about some other language entirely.|