Impressions from the iPhone Tech Talk in Berlin (kind of)

The bad news is, Apple needlessly slapped a “confidential” sign across the tech talk today, so nobody is allowed to write anything about it or post any pictures.

I think I can nevertheless write some thoughts I took away, without giving away anything about the content of the sessions. So what I write might have been inspired by the lectures, or by something completely unrelated, like surfing a web site or talking to people.

Some things to know first: I left early because I got bored, so I missed roughly the last two lectures. Also, I don’t have an iPhone myself yet, and my friends would perhaps even describe me as an Apple hater. I really don’t like Apple’s restrictive policies, and I don’t even like OS X, but that is a story for another post. The iPhone is nice enough to make me overlook the general flaws of Apple. For one thing, I gave up on mobile games development with Java because it became too tedious to support all the available devices. The iPhone is one device (OK, strictly speaking three: old iPhone, iPhone 3G and iPod touch) that has sold several million times, making it possible to develop useful applications targeted at one device only. And Apple really got a lot of things right, I don’t think any other phone comes close in usability.

If I don’t have an iPhone yet, it is because I don’t like the conditions of the T-Mobile Germany contracts. Specifically the UMTS bandwidth limitation seems silly, since the iPhone makes it possible to surf normal web sites. So I would expect the T-Mobile bandwidth to be consumed rather quickly.

Without a doubt, a lot of fun can be had with the iPhone, and a lot of fun applications already exist.

What follows is mostly me venting my frustration about having to use Objective-C. I had to say it somewhere… It is not the only thing I took away from the tech talk, but it was a tech talk after all, so you can guess about the main topics. I had a nice idea for a possible iPhone app while dozing in the lecture, and I also met some nice people, so going there was not all in vain. Oh, and I got a T-Shirt, too.

Objective-C, the strange beast

My main gripe, however, is the programming language. Most people I talked to say that it is not so bad, but my programmer instincts make me shy away from Objective C for several reasons. Granted, most of them probably sound like nitpicking and my objections might make me seem petty. But I have become a programmer out of laziness, and so I absolutely can’t stand it if a programming language is making me do stuff that isn’t necessary.

Header files (Shudder!!!)

Objective-C seems to be a strange beast: on the one hand it apparently is “fully dynamic” (Apple speech), meaning among other things that methods are not statically linked at compile time. On the other hand it borrows from C and C++, with ugly pointers cluttering the code, but much, much worse, forcing you to write header files for your classes.

I am not a language designer, but for the life of me, I can not get these two aspects combined in my head (dynamic linking and header files) – either one feature seems to make the other one pointless. Dynamic means you can modify classes at runtime, so what is the point of the header files?

I have programmed in languages without header files for 10 years now, so I can confidently say that there is no excuse for header files. I think they only exists because of the laziness of the developer of the compiler. But then again, those guys had several years to improve their compiler. What is up with that?

For the non-programmers: a header file basically means that I have to program every object and method in my program twice. Once to tell the compiler that it exists, and once to actually implement it.

It is certainly not difficult, but just as certainly it is not fun. For someone with my condition it becomes very difficult to do because I generally have a very hard time doing things that I see no point in doing.

No garbage collection

Another gripe is that Objective-C for the iPhone does not have garbage collection, so the developer has to take care of erasing objects by himself. Curiously, many people I talked to seemed to agree that this makes sense for a mobile device, because resources are so limited. Well, it seems the recommended maximum memory consumption for an iPhone app is 25MB. I have developed games for mobile phones in Java that had only 800KB available as runtime memory, with garbage collection. No problem whatsoever. A slightly more plausible explanation: garbage collection usually runs in a background thread, and having that thread constantly running might consume more energy. But honestly, I don’t believe it, that is just a weak excuse.

Also, you don’t even manage memory directly in Objective-C, but you have to manually take care of the reference counters. This makes even less sense to me, because I don’t think that is what makes garbage collection difficult. Rather, I would expect counting the references to be compiled into the executable. There might even be garbage collection going on in Objective-C, something still has to free the memory when the reference count has reached zero, after all. Again, this just reeks of laziness on behalf of the developers of the compiler.

Maybe inserting the reference counting into the executable would inflate the memory footprint marginally, but honestly, these days the size of the code is never the problem. Most memory is consumed by the data, for instance images that are being loaded by the application.

Hungarian Notation (Shudder!!!)

One more unbearable thing I have seen in code snippets from Apple: it seems it is customary in Objective-C to use the useless kind of hungarian notation. That means it is customary to call a widget UIWidget instead of Widget, because it belongs to the UI. Joel On Software has the ultimate essay on hungarian notation and how it should be done, mandatory reading for every programmer in my opinion.

Again, this might sound like a non-issue, but it makes me feel almost like the heroine of William Gibson’s “Pattern Recognition” upon seeing the Michelin Man: it is almost as if I am psychologically allergic to this ugliness and extremely bad taste. It sounds innocent if you see just one line, but imagine thousands of lines of code littered with hungarian notation. It is unreadable, unless you train your brain to just not notice it. But why should I have to do this to my brain?

More ugliness

I have mentioned the pointers, something I also haven’t seen in years. Going back to using pointers makes me feel like coding in the stoneage, and they also look ugly. In the same category as the header files fall the interfaces (forgot their real name, but they work exactly like the interfaces in Java). I see no need for them in a dynamic language, so please don’t make me use them. At least possibly one really can get away with not using them, I don’t know for sure.

Hope in the form of alternative programming languages?

Which brings me back to my original gripes with Apple. Is there hope of relief in the form of alternative programming languages coming to the iPhone eventually? Apple certainly hasn’t leaked any plans, and worse, they officially outlaw interpreters of programming languages. The reason is clear: with an interpreter of another programming language (for example a Java virtual machine), people could circumvent the Apple AppStore and get applications from other sources.

This alone does not prevent other languages, though, at least I don’t think it does. I think it would still be legal to use an interpreter just for one’s own application, without exposing it to other applications. Or one could use another language that compiles to Objective-C. One such language seems to be Objective-J. Still, I think the rule against interpreted languages at least slowed development efforts for alternative programming languages for the iPhone.

There are rumors that there will be an adapted (=restricted) version of Flash eventually, but it is not yet clear if it will be possible to write iPhone applications with it, or if it will just enable web sites.

I have found a Lua bridge to Objective-C, but it doesn’t sound as if the iPhone is supported so far.

Personally I still have some hopes for Javascript. There already is a Javascript interpreter in the iPhone, coming with Safari, that can also be instantiated from within an iPhone application. I don’t know yet how much one can interface with the usual iPhone features from Javascript, and if it is possible to run Javascript without actually displaying the WebView (Safari/WebKit). Most people I talk to about this are of the opinion that one should write iPhone Apps in Objective-C to get to use all the fancy features, but I am not fully convinced yet. I hope at least for some apps on can get away with Javascript (obviously not if you are writing a 3d game), so it might be sufficient to get one’s feet wet in iPhone development. Even just to be able to write some parts of the application in JavaScript would be a relief.

Meanwhile, I keep hopes for finding alternative languages for iPhone development. Please let me know if you find any. I probably won’t use Objective-J, though, because it seems too proprietary for my taste. If I learn a new programming language, I want it to be as universally useful as possible.

Ultimately it is the end product that matters, of course. I have programmed in the Linden Scripting Language for Second Life before, which is the crappiest language I have ever seen. Nevertheless it was fun, because the things you could achieve with it were so much fun. Probably it will be the same with iPhone development. Once I really get started and get to see results on the phone, Objective-C won’t feel so painful anymore. Still, I wish there were other options. Options makes me remember: I have also heard people say that XCode is not all that great either, and apparently it is not so easy to use alternatives. Too bad.

This entry was posted in Uncategorized. Bookmark the permalink.

2 Responses to Impressions from the iPhone Tech Talk in Berlin (kind of)

  1. nikolaus heger says:

    I am just now learning Objective-C – some of your criticism is unwarranted, some is half valid, and some is yes, 100% spot on.

    Header files: The Objective C docs say that header files are “the interface”, the definition if you will. There are some arguments towards keeping that separate from the implementation. I am not 100% convinced by this, but code duplication is kept at a minimum. Variables are only defined in the header, for example. I still find it confusing to have two separate files for every object. So in the end the main reason for header files is probably that C had header files. A stupid reason if there ever was one.

    Memory management: Yes. If you are used to garbage collection this feels like coming back to the stone age of computing. Am I programming a posix system from 1973 or the iPhone? There is no excuse.

    Pointers – that falls in the same category – it’s stupid.I get the feeling that in Objective-C, you kinda sorta pretend the pointers don’t exist. You pretend you are working with objects. But they are still there and no amount of denial makes them prettier. Along with alloc/retain/release it’s a bit of a nightmare.

    Some you didn’t mention: Overhead. There is a lot of “stuff” all over an Objective-C class – compiler directives, header file fluff, and other things – to write a simple class you end up with two files with lots of things in them. That’s all distracting from what you want to do: Define some objects and use them.

    I must disappoint you regarding alternative languages – it’s impossible to do unless Apple decides to wrap all libraries in some other language. There are many powerful frameworks in OS X and they are all in Obj-C. So if you used Ruby to program your stuff, you still have to know Obj-C in order to interact with the libraries. In the end most things you do have to do with libraries – you are very high up on the abstraction layer – a good thing – but the mountain of code you stand on is all through and through Obj-C, and some parts are even in C. The way I see it, Apple either implements an entire parallel universe of wrapped libraries, along with wrapped documentation – or Objective C.

    Losing the header files, pointers, and manual memory management could even make it into a modern language….

    PS: JavaScript is a problem in and of itself, it should never be the “solution” to anything ;)

  2. brundlefly76@hotmail.com says:

    I could not agree more in your assessment of Objective-C, it’s housekeeping is both completely unnecessary and extremely expensive. I see it in NYC every day it is costing companies millions over Java projects.

    Nickolaus – authoring a language interface to an SDK is not impossible at all, it’s common – expected even. Keep in mind that pretty much every major language (including Objective-C) at its root is interfacing with the same shared C system libraries at runtime.

    I personally don’t know what issues people have with Javascript are. I think alot of people confuse the related complexity of client-side browser development and DOM with *Javascript the language*.

    I find it pretty much the opposite of Objective-C – it’s extremely fast to develop in and works fine for me, and the competing runtimes get better and better performance every year.

    The only downsides are it requires the developer to know what he’s doing alot more, as it has no training wheels.

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=""> <strike> <strong>