In my spare time I like to program. Usually in C … which a lot of people find bemusing. My rationale is I spent my teenage years hacking assembly code on systems like the Amiga, so moving to C is like moving to a ‘high level language’. I never quite hopped on the Object Oriented bandwagon … so I’m kind of stuck in my old procedural ways.
I have one program I’ve been working on lately that is getting more complicated. For most of it’s life it’s been ‘command line only’. It creates multiple threads , opens lots of socket connections, spawn’s external subprocesses too. It’s been quite a learning curve to get it to work. Lately, I’ve started adding features to it to open a GUI window to provide status info. My first attempt was to simply add in some Xlib calls (yes Xlib 😉 ) to basically do the bare minimum to get a window up. That worked OK on linux, but I’d already ported the command line version to run on OSX … and the Xlib version did not really work on OSX.
So I thought ‘How hard would it be to turn my program into a Cocoa program?’. Cocoa is of course the main GUI enviornment on the Mac. In my earlier porting experience, I aas simply treating OSX as ‘another unix’ to do the bare minimum to port my program at a command line level. Using Cocoa was a whole different ball game.
So I thought I’d have a go. It’s quite a steep learning curve going from ‘procedural C programmer using vi as a development environment’ to ‘Using Objective C with Cocoa on the XCode development environment’.
I of course tried to make a very simple first app using an XCode tutorial. That proved a problem as a lot of the tutorials on the net are for XCode 2.x (rather than 3.x that is out now), and Apple have changed the Interface Builder enough to make all the old tutorials very difficult to follow.
But I persevered. I ended up getting the book ‘Cocoa Programming for Mac OS X’ which is actually a very well written book. That kind of gave me enough info to get some of the basics of Objective C (I still have a lot to learn).
After 2 days hacking at my code, I now have a working program. I thought it would take quite a bit longer. I still don’t have a clue when it comes to some of the philosophical arguments about object oriented programming … but ultimately I just want a ‘first pass’ that sort of works. Memory management is probably rubbish, and I don’t fully understand how the event loop is meant to work .. and I know I have a delegate set up … but I don’t really understand what a delegate is.
I guess working in XCode was actually moderately fun. It at least told me about the 170 warnings in my program (I really do leave a lot of unused variables all over the place). Debugging info was OK … but ultimately debugging multithreaded stuff is very difficult at the best of times.