I’ve been spending a fair amount of time in the last week getting up to speed with Objective-C and Cocoa programming, with the view of developing a couple of Mac- and iPhone applications.

I’m by no means an expert yet, but I think I’m starting to get my head around the fundamentals of it, and coming from a Java background I find quite a few things puzzling..
It’s quite obvious Objective-C is a lower level language than Java, and some of the things it does are in my opinion pure abominations, lets start with some of the things I dislike:

 

  • “Informal protocols”: Protocols in Objective-C is what we in the Java world know as interfaces. However, it has two types of protocols, formal and informal. The first type would be pretty much equivalent to a Java interface. The second type, well.. There is no way to force or assert that an informal protocol is actually implemented, it effectively only requires your object to respond to a given method signature, most of the time copy-pasted from the documentation. Argh!
  • Very, very loose typing in “messaging”: calling a method is called “messaging”. When you send a “message” (invoke a method) you don’t actually have to know whether the method exists on the target in the first place, if it doesn’t the call will simply fly out into the void and the code will happily continue executing. This can cause some very frustrating issues during development time.
  • XCode does a lot of “black magic” you can’t get at: If you decide to fully leverage XCode (the IDE), you can get a lot done for you. Only problem is, if it doesn’t have the expected outcome you can be stuck, to my knowledge there is no way to get at the core of this, other than through the point-and-click tools.
The things I do like:
  • Reasonably productive: I’d rather work in Objective-C than with something like Struts in Java. Despite some arcane behaviour, with XCode, it is actually quite a productive environment.
  • Apple’s Frameworks provide a lot of the basic plumbing – anything you could think of wanting to do, Apple has thought of providing the building blocks for you. The frameworks are very thorough and well thought out, it’s just a matter of learning how to leverage them.
I guess on the whole, my biggest issue with Objective-C and Cocoa has more to do with my personal background than Objective-C itself, the dynamicity and loose typing of the language, which are conscious design decisions, drive me up the wall coming from a Java environment.
Objective-C feels like a compromise between Object-orientation and scripting to me, but that’s probably the point.. Being from an environment where the compiler catches a lot of your potential mistakes, this can be a really contentious issue getting past the learning curve.
Personally, I’m not about to give up – I’m getting the feeling I am just on the cusp of being able to become really productive in Objective-C and Cocoa, and I already have a few ideas for applications I’d like to make.