Thursday, November 5, 2009

Why not Objective-C?

Patrick Logan can't understand why projects use C++ rather than Ojective-C. Neither can I.

For the 95% (or more) of code that isn't performance sensitive, it gives you expressiveness very close to Smalltalk, and for the 5% or less that need high performance, it gets you the performance and predictability of C.


Vlad Bayan said...

Maybe because ObjC code is hard to read?
If you show some ObjC code to ten non-ObjC developers, what will be their first reaction? =:O

"Code is read much more often than it is written" - and this is really important in commercial projects.

Marcel Weiher said...

Totally agreed, code is read much more often than it is read, which is why (a) keyword selectors and (b) verbose, meaningful message names are so important.

This is why:

[a setObject:@"foo" forKey:@"bar"];

is preferable over:

a.put( "foo" , "bar" );

Without having memorized the API, tell me which is the key and which is the value in the Java version? Now multiply this effect over a large code base.

Of course, the Smalltalk version is somewhat nicer still

a setObject:'foo' forKey:'bar'.

This keeps the readable keyword syntax and ditches more of the syntactic noise.