To Objective-C or Not to Objective-C

iPhone Programming Languages

With the iPhone (and Mac) programming, you have the choice of C, C++, Objective-C and Objective-C++.

I say, Given the Choice, but the reality is that you will be forced to use some Objective-C, love or loathe. Personally, I am growing (slowly) to like the language, but I think it will depend on your background.  To a C, C++ and C# programmer, Objective-C does seem a tad crazy - because from my point of view, I don’t want a method (read message) to be silently swallowed when I try and apply it to a nil object.  I assume a Mac bod, would explain the reasoning to me behind this bit of design, but I imagine that, Objective-C being quite different to C and C++, it might still not make any sense.  And the lack of any enforced constructor logic is a bit annoying I find.

That said, as I say, I am starting to like the language - Cocoa Touch is very powerful and I am starting to enjoy using Interface builder, although I find XCode acceptable and the debugger somewhat abysmal (but then it could be that I simply need to dig to learn how to use it properly).

Wire Whizz fighting the System

Originally I shunned Objective-C and embraced Objective-C++, principally because I could use my existing 3D engine, written in C++ and could interface at the bare minimum with Objective-C and the underlying OS.  The result of this shunning, is that I have spent ages faffing about re-inventing the wheel.  If you look at some earlier posts, you will see that the menus are somewhat different to new menus and this is because they were originally being rendered by OpenGL and my 3D engine and now I am relying on Cocoa.

Eventually I became fed up of the slow and painful turn around, creating 3D scenes for menus, fixing up textures, exporting the 3D scenes, loading them and hooking them up. It was also likely to be a nightmare when it came to localisation.

Wire Whizz Conforms!

At length, I ditched the OpenGL menus in favour of Cocoa menus.  This was something of a stiff and painful leaning curve, but after around four months of re-writing the menus and the game ‘housing’ in Objective-C and Cocoa, I am reasonably well versed with both, so far as I need to be at this stage.  I had Wire Whizz working, I had the game slowly approaching completion and I massively overhauled the entire project.  My advice to you is to not fight the system, take it on the chin that you need to learn it, and do so first or while creating your app/game or whatever.

That said, the guts of the game are in C++, because I still don’t 100% trust Objective-C or myself yet, because there is some small overhead with function calls in Objective-C over C/C++ and because the game and various modules were already in C++.

In ditching the relatively pure OpenGL/C++ version of the game, I ended up with an entirely new project.  I worked largely on the menus after getting the engine incorporated, building and a context active.  I then had to take the portions of game code from my old application and integrate them with the new framework.  It’s better, but the game would have been finished by now had I done things differently. I wouldn’t know as much however and localisation would be hellish.

Do it the right way first - it’s (almost) always quicker!

Leave a Reply