Thinking outside of the .NET box

In the recent months I was working mainly on iPhone projects in my spare time abd recently I was lucky enough to cut some iOS code for work too! Definetly time to blog about my encounter with Objective-C, XCode the Cocoa and all the other wonderful things that come out of Infinite Loop 1 in Cupertino…

My first encounters with the iOS environment about 2 years ago left me with a feeling of ” wow this is old style!”. Header files, pointers, no automatic memory management… It took several attempts to actually get into it. I quite like reading a book about a programming topic. That’s the reason I picked up a book by Aaron Hillegas about Cocoa and OS X programming. It is definitely a good idea getting a basic understaning of Objective C and Cocoa before delving into iOS.

Some of the differeces are striking and you are definitely forced to think outside of the box as a .NET / C#/ Java programmer (…that’s how I would describe myself…). Weak typing is a shock at first. It took me right back to my roots as Perl/Javascript coder. After a while you start enjoying the freedom. It is actually quite a good balance between warnings on the compiler side and freedom in the runtime.

Cocoa tends to use helper classes and delegates¬† instead of inheritance to build frameworks. This is described as the KITT versus Robocop approach by Aaron Hillegas’ book. You have to read it yourself to appreciate the analogy (did I mention it is a good read?). That is something I have defintitely taken over in my day to day .NET programming. If detaches your design from the class hierarchy.

Some other concepts like Categories and Key Value Coding can be found in .NET in a much more refined version. It is however refreshing to see how simple you can achieve similar goals.

Memory management is definitely the hardest part of the iOS journey for me. Having to allocate and free memory has not crossed my mind for a long time. Cocoas approach (using a retain/release) model makes it however bearable.

You are rewarded with a remarkebly productive environment. The power you gain from beeing “close to the machine” has surprised me. I have long defended the claim that todays Java and C# jit compilers build executables that are as performant as native compilers. Although I have not measured my obersvations I beileive on small devices the difference still matters.

If you want (or have to) develop for iOS you have choices these days. However in my experience it is hard to beat the results you get from using XCode, Objective-C and Cocoa. Give it a try.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>