With the coming out of Leopard, I’m truly excited about the new programming features, it gives me lots of ideas about applications I’d like to build.
But each time I dig into the Cocoa Fundamentals, I’m just having a heart attack. Why desktop programming is still stuck in the 80s and so unproductive?
Here is a simple Cocoa command-line program. Given a series of arbitrary words as arguments, the program removes redundant occurrences, sorts the remaining list of words in alphabetical order, and prints the list to standard output.
$ filter a z c a l q m z
a
c
l
m
q
z
Simple isn’t it? Here is the code in Objective-C using the Cocoa framework:
int main (int argc, const char * argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSArray *args = [[NSProcessInfo processInfo] arguments];
NSCountedSet *cset = [[NSCountedSet alloc]
initWithArray:args];
NSArray *sorted_args = [[cset allObjects]
sortedArrayUsingSelector:@selector(compare:)];
NSEnumerator *enm = [sorted_args objectEnumerator];
id word;
while (word = [enm nextObject]) {
printf("%s\n", [word UTF8String]);
}
[cset release];
[pool release];
return 0;
}
Erk! It just gives me spots, look at all the code you have to write to setup the objects. Funny enough, the documentation says:
The first thing you probably notice about this code is that it is short, perhaps much shorter than a typical ANSI C version of the same program.
Short? Here is what I call short:
ARGV.uniq.sort.each { |e| puts e }
Objective-C 2.0
Leopard comes with Objective-C 2.0 that features garbage collection and better iterators. But in the end, that won’t make much difference — it might remove a couple of lines in the above code. Despite its dynamic features and its huge libraries for Mac OS X, Objective-C is still a low-level programming environment.
In understand that in Mac OS X, power comes from the tools which removes part of the burden of writing code but it’s not that ideal.
Ruby and Python Bridges
Leopard also comes with Ruby and Python Obj-C bridges so that you can — in theory — write Cocoa applications. I say in theory because any attempt so far has failed.
I guess the gap between Obj-C and high-level languages is just too big and makes inter communication complex.
No Flame Wars
I’m not starting another flame wars about programming languages, performances issues or compatibility. The above two examples are not just on the same abstraction level.
I just hope that in the future we’ll see high-level programming environments wired into OSes so that we can write apps faster. In that regard, Microsoft has done a pretty good job by giving C# more and more expression power without breaking low-level compatibility.




Add New Comment
Viewing 8 Comments
Thanks. Your comment is awaiting approval by a moderator.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Add New Comment
Trackbacks