Pages

Thursday, March 12, 2009

a Java developers Objective-C comments

This my language flame post ;)
So last month I have started developing for iPhone. In order to do so you have to use Objective-C because by default iPhone does not come with Java Virtual Machine. These are the things I most stumbled on Objective-C:
1. Square brackets !
When procedural language people see Lisp code first thing they say is : "What's with all that parentheses ?". Objective-C allthough being procedural, object oriented, language makes me say "What's with all that square brackets ?". You use square brackets to send messages to methods they are soon all around your code and look ugly.
2. Defining Classes and Properties
Objective-C adopts the single inheritance model like Java but, you have to define your classes in "the old header" files and implement them in a seperate, C file. There is no one public class for one file enforcement by the language so you are free to mess your class definitions and go "Where did I defined that ?".
If you want to define a property to use in the interface builder, you have to define it in three places. One in class definition, one to mark it as UI thing and the last is to generate getters, setters.
3. Memory Management Model and When Things Go Wrong
Hardest problems to spot for a Java guy like me was the pointer (or memory) access problems. You have to know what "retain" and "release" does before you start doing anything.
And Objective-C does not have the Java's detailed stack traces so when things go wrong you can have serious headaces and need to hit your head to walls. 
Still its realy fun to develop for the iPhone. Where else you can build a application that responds to your swings ?

No comments:

Post a Comment