Objective C


Over Thanksgiving vacation I was thinking I should maybe play around with Swift and maybe try to create a basic iPhone app just to see what the programming model was like. I headed over to Code School to see if they had a free course I could play around with. Unfortunately they didn’t, but I did see the Objective C course over there. My thinking was given that most iOS apps were written in that, why not do that course.

Apparently I have been doing Java for too long, cause I really thought man this language just feels old and has as Venkat would say there is a lot of ceremony in it. It just feels like there is a lot of things that don’t need to be there. For example you declare strings @"String". Why do I need an @ sign in front of a string, it is just a hard to type character on the keyboard which isn’t exactly going to speed up your typing. Also everything being prefixed NS like NSString. I suspect they are still keeping the old C Strings around as well, so now you are specifying with the @ that it is an Objective C string type. I also had forgotten how annoying it was having to deal with declaring * for your strings and arrays. There is a lot of be said for everything in Java being a reference (save for the primitives). Now I need to be thinking do I need a pointer for this object or not. I guess I saw another note that the * is actually denoting that it is an objective C object vs a C object. (At least according to code school). If that is the case then it is sort of overloading the pointer from C which doesn’t make things clearer.

Also creating a new object is pretty annoying you have to both allocate it and init it. Seriously no new you have to “send 2 messages” every time you create something new as shown here: NSDictionary *emptyDictionary = [[NSDictionary alloc] init];. So like I said lot of ceremony. And for Booleans they use YES and NO instead of true and false. Not a big deal but seems an odd choice, though still better than C’s 0 and non zero values. And having to do both headers and implementing files seems weak as well. Sometimes in Java we do interfaces, but I like not having to do them for every single class, you just use them when it makes sense from an inheritance standpoint.

What did I like about it? Well I did like how you can just declare a dictionary with the elements in it, instead of having to construct it and add elements to it. Java’s maps need this type of thing. An example in Objective C is: NSDictionary *appRatings = @{@"AngryFowl": @3, @"Lettertouch": @5};. The for in statement is nice similar to Java’s for :. I also like their closures where you can just pass a lambda function around with ^(NSString *word, NSUInteger index, BOOL *stop). That is something they definitely beat Java to and I think the syntax is nice for it with the ^ and function declaration seems as good as Java 8’s ->.

The other thing that I am unsure about is the sending a message thing. I found myself wondering are you actually sending a message like in an event oriented model or are you just calling a method of function? The syntax felt a little odd compared to most languages if you are actually calling a function [objectName messageName]; If that is a method call it is some serious ugly ceremony, but if it is some sort of message passing then maybe that would justify the odd syntax. When you end up with a bunch of nested calls you have some seriously ugly code. Code school has this quote:

Note: “Sending a message” is sometimes referred to as “calling a method”. You’ll find Objective-C programmers using both of these phrases to mean basically the same thing.

Maybe it doesn’t matter, but I actually do want to know what is going on under the hood just out of curiosity.

Anyway in the end I am glad I took the course. As always Code School does a great job presenting the topic. It was interesting to get a feel for the language, but it definitely feels old. It is easy to see why Apple is moving away from it and towards Swift a much more modern language. So I guess I still want to sit down and play with swift and write a basic iPhone app to get a feel for it. Based on playing with Objective C over thanksgiving it sort of feels like a waste of time to invest any effort playing with the language, it feels old and nothing I want to spend a lot of time fooling with. Might as well use the latest and greatest if you are going to play around with it.


One response to “Objective C”