the iPhone quest – going from C++ to Python to Objective C
I’m on a quest: I want to learn iPhone development because I’ve got too many fun ideas for little apps. Nothing amazing, but I want to beef up my skills enough that I can whip out an app in a few days, if I’m so inspired.
So I’ve started learning Objective C. And man, it has its ups and downs.
I come from a C, and then C++ background – years of hacking on the Mozilla / Firefox codebase. Since then I’ve spent 4 1/2 years writing a lot of Python. I fell in love with Python within the first few weeks of learning it, probably because everything is just so much easier than it was with C++. I could throw together a very powerful little script in a matter of minutes. I won’t go more into my love of Python because this is more about Objective-C.
My impression so far is that Objective-C is a unique hybrid of dynamic and non-dynamic languages. Yes, it is C at its core, so of course all the usual compile-time C issues and benefits are there, blah blah blah. But, the core language itself is fairly dynamic, including dynamic method dispatch and a healthy amount of introspection. Yes, you can look at an object and see if specific methods exist or not, and if so call them. You can call methods dynamically, meaning you can look up an arbitrary method name by string, and call it.
But in all of this I’ve only mentioned methods and not attributes. Objective-C does seem to suffer from the getter/setter disease that plagues Java, though it disguises them with the name property. This kills me. getters and setters drive me crazy because 99% of the time you want direct access to a object’s instance variable (an “ivar” in Objective-C), and the other 1% of the time the object wants to interfere with that access. Adding a wrapper around every attribute access adds an extra level of abstraction and frankly, code, that seems totally unnecessary.
Thankfully Objective-C 2.0 has some nice @property and @synthesize shortcuts that mean you’re not typing the getter/setter code, which honestly is half the issue.
I’ll post more on these issues later.