Quick thoughts on writing Objective C

Playing with my new Mac, this is my first time writing Objective C code in 15 years, and C or C++ code in nearly 10. Some quick thoughts after finishing Your First Mac Application.

  • Header files? In 2011? That require forward declarations of classes? Ugh.
  • Objective C properties are handy syntactic sugar. I have no idea what “synthesize” really does, but I like the result.
  • Static typing is awkward. I’m prefering dot style for properties
    self.track.volume = sender.floatValue;
    But if the type of “sender” is id that doesn’t work. I have to fall back to
    self.track.volume = [sender floatValue]
    and rely on Objective C magically not type checking method names on id. Objective C has duck typing, sorta, but not everywhere.
  • Manual memory management continues to suck. Apple has papered over it in various ways, with retained properties and autorelease and now ARC. But the fact that the programmer is even aware of reference counts is a serious flaw in the language. Seriously, every other OO language for 20 years has had garbage collection. Hell, even C languages have had automatic garbage collection via a conservative collector like the Boehm collector. WTF is wrong with Apple that their development language requires manual memory management?
  • Xcode 4.1 is a pretty solid IDE. I could drop into it with just a basic tutorial and understand most of what was going on quickly. The Interface Builder stuff so far seems OK, although we’ll see how it works with real code. I’m impressed with how one can do complex user interface constraints entirely graphically.

2 thoughts on “Quick thoughts on writing Objective C

  1. Apple introduced garbage collection with “Objective C 2.0” and Mac OS 10.5 in 2006. Apparently it never worked very well. They’ve disposed of it in favour of ARC this year with Mac OS 10.7.

    Personally, I grew up with C, so I’m happy with manual memory management: if I retain something, I later have to release it. Simple.

    b

  2. Thanks for the comment! I grew up with C too, but have long since gotten used to the computer doing the memory management work for me. Releasing at the right time is not always so easy in complex code and is the source of several new kinds of bugs and security problems.

    Hopefully ARC will work out.

Comments are closed.