The Beauty of Objective-C?

This is a tech blurble.  If you’re not interested in tech blurbles, you can skip this one.  Sometimes it reaches peak blurble and it flows out over my blog and then the tide recedes for a while.

I really love Ruby.  Something about Ruby does it for me. I’m not clear what it is — the readability, the list comprehensions and lamda functions, the easy way to get things done, the Japanese language syntax to a long line of calls, the ability to shove an entire program into one super long line of code*, or what it is about it. I just enjoy programming in Ruby. It doesn’t fight me. It generally does what I want it to do. Plus yield! Oh yield, you crazy functional programming primitive you. Occasionally, in my Python code, I will write something in Ruby syntax (because it’s completely possible) and leave a comment like:


# Ruby-style list comprehensions FTW yo!

It’s childish.  But that’s what code comments are for — childish things.

My second favorite language is Python. It has the all powerful master of the universe ctypes class that makes it such THE tool for manipulating operating systems. All the power of C, none of the hassle of C! It goes best with Advanced Programming in the Unix Environment.  The two are like a fine peanut butter and jelly sandwich.

Toss in C and some assembler and I have a full toolkit to really cause some damage and occasionally write some code.

I have been filling my head with Objective-C for the last two weeks and working through Cocoa Programming from Pragmatic Bookshelf** to learn the beast. In general, I would call this a success, as given 10 minutes I can write a small program now, but I find the language clunky and cludgy the exact same way I find Java clunky and cludgy. I can’t tell if it’s just me. It might just be me.  I feel a bit like I have been driving a nice reliable sedan for a while in Python shape or Ruby shape (depending) and suddenly I’m in a Ford Pinto and any moment it can catch on fire. Essentially, it’s C mashed together with Smalltalk using wacky Simula bracket syntax and mixed up with a huge number of toolkits (legacy and not) to turn this mess into this big development platform for mobile. The wikipedia page does have a decent overview of the programming primitives for the wary.

It’s not so much that it’s like Simula. What is bothering me is the sheer amount of accounting. One needs to remember if the call is a class method or an instance method and call appropriately, remember argument names, mess with properties, set the memory model correctly for all said properties which may be different depending on the nature of the class (mutable, not mutable, copying, etc), remember to manage memory in dealloc() when the class is disposed, create models where the class is properly created and hangs around, manage different forms of class instantiation and other bookkeeping that gets between one and actually doing work. I am vaguely reminded why Java turned me off so badly — but worse.  Toss in that the book I am reading is married to beautiful code — can we eliminate ALL LOOPS and DECISIONS in this application to make it SUPER COMPACT? — and it’s headachy.

From my standpoint, there’s some major pros — one can theoretically consume C-based libraries and packages and even just give up and write the guts code in C — and some cons — getting used to the weird syntax, and having to do all this paperpushing to bring up an application — to working this way. Deep down it just feels slow.

I have this feeling people are going to get tired of working this way and do what they did with Java: make Java implement any other language, please any other language, on the JVM, then Java.  Just make the bad and hurting go away.  Python => JPython.  Ruby => JRuby.  Hell, one can do Grails stack on the JVM with groovy which pretends to be Java with Spring but is more a Ruby on Rails stack then anything else.  Clojure, last week’s toy of the week, is LISP — dear God, LISP!!!!! — implemented on the JVM!  LISP!  Did I mention LISP?

Meanwhile, I am merely whining about the incomprehensibility of Objective-C.  I am getting enough of the hang of it to read through stackoverflow articles which pushes me out of newbie and firmly into “can cause mayhem.”   And then past the language barriers, mastery of the data structures (NSDictionary, NSArray, etc).  And then — the world!

(I found an article on how to do list comprehensions on the NSArray class in Objc-C here.  It is possible.  Thank you magic Internet.)


* Which, arguably, I can do in C.
** I will post an in-depth review.