Koz Speaks

Cocoa and Objective C

Lately I’ve been spending my spare time writing Cocoa code, more on that later. On the whole I’m finding the transition a little strange, but it’s always fun to learn what other frameworks do.

The extremely long method names take a little getting used to. To retrieve an object from a dictionary you use [foo objectForKey:@”bar”], this takes some adjusting if you’re coming from ruby (foo[“bar”]) or Java (foo.get(“bar”)).

Garbage collection can’t come soon enough, while retain/release memory management beats the pants off malloc/free, it’s still too much work and even apple gets it wrong. Those of you thinking garbage collection is slow or inefficient, should read Jamie Zawinsky’s essay on the topic.

I find the handling of nil completely bizarre. First up, you can’t put nil into a collection, you have to use [NSNull null] for that. But the part that really confuses me is message sending.

If you send nil a message, any message, it’ll return nil. Some people like this but I’ve just found it obscures the source of an error. It lets your entire model slowly be swallowed by a single null reference, like some strange cross between Strangelets and cancer.

Overall, I’m enjoying Cocoa, there’s some serious gaps in the documentation and tool chain, but it feels miles ahead of the last desktop programming I did.