Thursday, January 13, 2011

The Spiritual Discipline of Debugging

I've been working on a software problem off and on for many weeks now. It should have been done a few weeks ago, but I keep getting it not quite right. It involves transforming about 100 million lines of data from one format to another, with some complicated rules. Mostly it works, but there are a few lines that convert wrong.

Each time that it fails I have to look at my program and figure out what I did wrong. I was working on it this morning when I had an aha about the debugging process itself. Successfully debugging your own code requires several habits:

1. Be methodical

2. Look at the whole problem

Up until this point, it is could be considered just a mental discipline. But there is an important habit that takes it out of the purely mental domain:

3. Approach your code as if anything you did has an error.

This last habit is humility. The debugging "Eureka!" came when I looked at a line of code that I had reviewed ten times or more, and always assumed that it was of course correct. I decided to think about it one more time, and suddenly saw an error. The program may not be done yet, but I definitely found an important bug. Not because I thought smarter, but because I thought more humbly. The Aha was about the debugging process itself. If you had asked me, I'm not sure I would have emphasized humility as critical to the debugging process.

I leave the application to the rest of life to the reader.

No comments:

Post a Comment