11/14/01

There seems to be a disrespect for Carbon among many OS X users. The refrain I keep hearing, not necessarily applied to our software but to many other people’s software, is “why didn’t you use Cocoa?”

The argument, from people who like to tell developers what to do, is that Cocoa apps are faster and more OS-X-like.

Now, I like Cocoa alot. I’ve been learning it a little bit at a time when I have spare moments. The more I learn the more I like. I’m starting to believe the hype that, once you learn Cocoa, you can build apps more quickly in Cocoa than with any other framework.

But I don’t believe it’s faster. Objective-C is a dynamic, object-oriented language. Though I don’t have hard data, it’s a rule of thumb that straight C outperforms object-oriented languages. There’s a certain performance overhead associated with object-orientation—and my guess is that Objective-C, especially because it’s so dynamic, is far from being an exception.

It was true at first that Carbon lacked certain features present in Cocoa—Services support, for instance. But now Carbon has all that stuff.

Again—this is not to dis Cocoa. Were I starting a new Mac-only app, there’s an excellent chance I’d use Cocoa.

But there’s a certain lean elegance to a well-written C app that should not be dismissed easily. You get a finer level of control because there’s less going on behind your back.

A good C app is written with object-oriented principles, only you use structs and callbacks and function pointers. You do a lot of factoring, respect the principles of encapsulation and MVC design, etc. You don’t have to give up good programming practices just because you use Carbon.

What I’m saying is: Carbon is cool too. Don’t disrespect it. So much depends upon the developer.

Another benefit to Carbon, not to be taken lightly: if you want to port your app to Windows or Linux or whatever, starting with a Carbon app is easier than starting with a Cocoa app.

I’m lucky in that my first lessons in good programming practices began over 20 years ago. My parents were both programmers, and I was learning BASIC on my Apple II Plus.

Many dinner conversations could be summed up with these famous words: “Goto considered harmful.”

I was thick-headed. I preferred goto to gosub. (I was also 12.)

I’m an award-winning programmer. I even still have my medal.

In the eighth grade I went to some sort of programming competition in Delaware. There were kids from all over the state.

Our task was to write a BASIC app that sorted an array of strings.

I knew about a few sort algorithms, but we had a time limit, so I went with the easy one that I knew I could do: the bubble sort.

After I turned in my floppy with the program on it I decided to get out of there. There was no way I was going to win. Even though my program worked, surely other kids were using faster, more sophisticated algorithms.

So we went home.

Later I found out that I won. Someone from my school accepted the award on my behalf.

My conclusion—which, looking back, seems rather harsh—was that sometimes you are the one-eyed man in the kingdom of the blind.

14 Nov 2001

Archive