« May 2005 | Main | August 2005 »

July 27, 2005

You See I Am Trying To Be Objective About It.

Listen to this articleListen to this article

It was an unsettling feeling, one I was sure I had experienced before.

Seven days ago today, I boarded the good-ship Xcode bound for the land of Cocoa. I was promised a bumpy but nevertheless enjoyable ride over well charted sea, enjoyable smalltalk and no bugs. Life would be wonderful and applications would spew forth from the finger tips of those who chose to take the journey.

Seven days later, I'm in pain. I'm hurting. I'm surrounded by square brackets. I have a hard time keeping track of my memory (maybe it's alzheimer's?). I wish I new what was wrong with me but even the good Dr. GCC seems to have a heck of a time diagnosing my condition. I have a sneaking suspicion it's a form of jet-lag - I feel as though I've travelled back in time (about 15 years to be precise) but I'm not sure.

Humour (such that it is) aside, I've been getting into Objective-C the past week as there's a project I'm about to start working on that is targetted at Mac OS X and will be written in said programming language. So, I thought I'd go head first and use Xcode as well. Ouch, ouch, hurty, hurty. Why do I feel like someone just cut off my arms and stuck red hot pokers in my eyes? To be honest, I think I should have started off with TextMate and GCC. But nevertheless I'm percervering.

I do like the Smalltalk like features such as dynamic binding and the calling syntax is quite simialr too. I don't care much for the use of square brackets - though I'm not sure I could come up with anything much better for a language that is (or at least was) essentially a pre-processor for a C compiler. The fact that I have to use pointers all over the place is particularly irritating too.

Ahh yes, I was once a member of the K&R club: First C; then C++. All those calls to malloc & free, new and delete. Endless hours of trying to remember what happens when I use array indexing on something declared as int **. In the end though, I guess it comes down to what you're used to and for the last 6 years (I think?) that's been Java; a language that for all it's short-comings (of which there are plenty), is a pretty simple language to learn and understand - at least it was for me anyway. I've become acustomed to garbage collection, packages and object references (the last being syntactic sugar mostly) and I like them. And of course then there's IntelliJ and Eclipse to help me out, suggest class names, think for me.

So it came as rather a shock to the system to go back to an IDE that seems to require soooo much configuration for apparently soooo little benefit, a language that forced me to think about when to call release to cleanup unused objects, and an overall environment that let me compile and run something that, on subsequent inspection, didn't even seem to be valid code - more likely a "feature" of Xcode than any underlying problem with GCC or the language itself.

Of course many of you will argue that I've forgotten what it's like to be a Real Programmer™; that it's character building. To this I say phooey. I was once an assembler programmer and I loved it. Then I became a C/C++ developer and I loved it. Then I moved to Java and never looked back (well maybe once but nobody saw me do it so you can't prove a thing). Moving to Objective-C is thus a painful yet disturbingly rewarding experience; like pulling out the old Commodore-64 and playing Galaga: The graphics suck but they're cute and the game is nevertheless fun to play.

So, the things I like about Objective-C so far:

  • Dynamic dispatch - ie. run-time method binding;
  • Categories - adding methods to objects at run-time;
  • Smalltalk-like calling syntax; and
  • self - I don't know why but it's somehow more appealing (or just different) than this;

Things I dislike about Objective-C so far:

  • Manual (yes as far as I'm concerned even reference counting is manual) memory management;
  • Square brackets;
  • + and - for marking static and instance methods respectively;
  • @whatever - smacks of pre-processor hackedy hack hack hack; and
  • Needing to manually call the super "constructor" - it's not really a constructor so, yes, I know why it's necessary but it still sucks.

But in the end, who can resist the sexy look-and-feel of Mac OS X apps? Not I. And I want to try my hand at creating some so what better way to do so than Objective-C/Cocoa. I'm assured that once I get into using the Cocoa stuff, life get's a lot more fun and interesting, fingers crossed. Or perhaps I'm just too old and grumpy ;-)

If anyone has tips, links, experience they'd like to share on how to make this a more pleasant journey (no, shut-up and take it like a man doesn't count), please please please let me know.

July 23, 2005

Not Writing Myself Off Just Yet

Listen to this articleListen to this article

Finally, after some travelling, I'm back in Oz having spent some time in Ladakh (Northern India), France, U.K. and Canada, all the while trying to write my first technical book.

The book (yet to actually be published mind you) was handed to me by Jon Eaves, no doubt meant as a cruel joke or perhaps punishment for some as-yet unspecified crime I must have committed ;-)

It has been a bit disheartening at times. For a start, I knew that I knew nothing about writing before I started but I now know how little that actually was. I take some comfort in the knowledge that as a complete newbie to the whole writing game, I wasn't supposed to have known anything anyway. Having never completed a degree (I left school at age 17 to start working) and thus never having written much if anything except for my occasional blog entries (and whatever is necessary for work), my capacity to fill pages with words was (and probably still is) severely limited.

Then of course there is the tragic development process that is book publishing. For a start, you have no idea what they actually want so you do your best and start handing in chapters. As the weeks go by and you hear nothing in the way of feedback, you start to worry so, inevitably you spend more time on each chapter trying to get it "right". Eventually the chapters are returned to you. Some are great, some need a bit of work and others are unrecognisable, let alone unintelligible to even me, the original author! I'm not sure how to resolve this problem though as everyone I speak to complains about the same thing.

I should also never have travelled while writing my first book: I discovered that I'm a single-threading processor, just as the stereotype for my gender suggests. Though to be fair, I'm not sure this really contributed as much as simply Not Having a Clue™.

I learned that standing up in front of people and giving a talk, a presentation or even teaching a class, pales into insignificance when compared to writing a book (at least for me anyway). Get my gums a flappin' and there's no stopping me; put me in front of a computer to type out a chapter and ..................................... Exactly! Nothing. Nada. Bupkis. Zero. Zilch. Nanimo. I found myself having to talk out loud to an imaginary person just to get my brain into gear.

Then of course there is the subject matter: Algorithms. A topic covered by so many books that surely only a mad-man would attempt another. This one is different though. It attempts to cover each algorithm at a conceptual level in a way that most people should understand. The code itself is unit-tested and the implementations are not merely a re-hashing of C-code just to get the word Java on the cover. So in that sense I'm quite proud of the effort - I'm yet to see the final product.

On another positive note, I think my coding has improved. I'd like to say that I experienced some epiphany and suddenly became a better coder but alas, the motivation was far more down-to-earth: I'm lazy. Having to explain code in words can be difficult and at times a little, shall we say, uninteresting so, the smaller and simpler I can make the code, the easier it is to explain. The down-side is that my coding style changed about 2/3 of the way through writing the chapters. Oh well.

Fortunately I also had James (another book-writing newbie) helping me out. Unfortunately we ended up on different sides of the planet. Fortunately, against all advice to the contrary, our friendship surived with flying colours; If anything it's made me realise how much better it is to regularly pair on things.

And lastly, I think I'd like to write another book though my approach would be very different. We'll see if anyone is willing to risk it a second time. In the meantime, it's back to my greatly-missed training schedule, get a haircut, and get a real job.