Learning Objective C
March 8th, 2008
With the release of the iPhone SDK, it’s clear that I need to learn some Objective C. I have been meaning to pick it up for a while now, if only to write Mac OS X Desktop Apps. But coming from Ruby, and not knowing C, its a little weird. I have a brain dump of initial thoughts as I trudge through my learning process that I will document here.
First of all, memory management? Ruby has way spoiled me here. Having to manually allocate and deallocate memory manually seems like a huge pain the ass. But on the other hand, maybe that is one reason that Rails apps take need 50MB of RAM just to be present.
The bracket method invocation syntax is pretty weird to me. As is the method declaration syntax. I’m getting used to it, I am starting to see why it’s done that way. But its still ugly.
1 2 3 4 5 |
// method declaration - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { // method invocation [myObject touchesBegan:someTouches withEvent:someEvent] |
The “every argument is named” thing, is actually pretty nice. But the syntax to hook all that up, and strongly type every argument, is pretty ugly.
Lastly, for now, the language just seems needlessly verbose. For example, to create a new Photo:
photo1 = [[Photo alloc] init]; |
I much prefer ruby’s Photo.new. Or to get objects out of an NSArray object you actually have to do something like:
[myArray objectAtIndex:123] |
Learning a new language is a great mind expanding exercise. But I hope to, one day, learn a language that didn’t make me wish I was using ruby instead.
March 8th, 2008 at 03:33 PM
This is part of the problem with Objective-C. Obj-c now has GC but good luck finding book that covers the new changes.
March 9th, 2008 at 12:57 PM
Don’t get too comfortable with garbage collection if you’re thinking about coding for the iPhone, as it doesn’t support it. You have to release and retain manually … ugh.
March 24th, 2008 at 01:10 AM
Sorry for bothering you with fleximage related question, but could you tell me how to retrieve the width and height of an image to use it in custom processing?
My complete question is here (if you fell you are specially patient for noob questions today):
http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/170313668581559c/a67b29a882079995?hl=en#a67b29a882079995
Thank you for your patience and for creating this awesome plugin