Saturday, September 13, 2008

Crashing More Than Just Castles

With the recent release of the game Castle Crashers, there has been some controversy about bugs in the game. This has led me to think about the difficulty of programming.

This topic has been exacerbated by a recent event at my work. I've been learning how to do iPhone/iPod Touch application development. It is really interesting. It's also very nice to be learning something new. Development has been going really well, but then yesterday I hit a nasty problem. The program is crashing due to a memory issue I cannot find. (For those interested: somewhere something is trying to free an object which has already been freed.)

I spent several hours wrestling with this problem. The debugger was of no help, nor were the tools for tracking objects and memory leaks. I tried all of my usual techniques, but just couldn't find the problem. After I had spent an extra two hours at work, I decided that the best thing to do would be to go home. On Monday I plan to go back and take the component completely apart and start from scratch. Very annoying.

There is a tried and true method for fixing really confounding problems like this, and I'm hoping that it will work in this case as well. The method is this:
  • Go home.
  • Get some sleep.
  • Get the problem out of your head for a while.
  • Go back and take a fresh look at it.

I am sometimes amazed at how complex programming can be. Computers are complicated enough to begin with! After taking a class in which we built an 8-bit computer from CAD tools, I often think it is a miracle that computers work at all! Then on top of that you add OS software, all sorts of libraries, and your own code... there are many layers.

Unfortunately, one of the truths of programming is that there will be bugs. For non-trivial programs, it is asymptotically hard to find and fix all the bugs in a program. Luckily, like a squeaky wheel the worst bugs usually reveal themselves and are subsequently fixed.

But despite the many bugs and occasionally rip-out-your-hair problems, I love programming. It is a euphoric experience to be able to see the results of well-written code.

P.S. Castle Crashers is a great game!

UPDATE: I figured out the problem with my iPhone program and had it fixed within an hour of showing up to work. Like I said, tried and true.