What your bugs are telling you

Last night I was doing some work on the PICO MIDI cheesebox when I found a bug in the way that note values are assembled when the box is generating random tunes. I came up with a quick fix and opened up the relevant part of the code. And then I stopped. I was wondering if, in the absence of a commercial imperative (after all, nobody’s business is hanging on this code) I should be wading in just right now. Perhaps it would be better to sleep on it and then fix it in the morning.

I put the question to Twitter, and got a variety of replies. I didn’t make it clear that the bug was not affecting anyone else at this point and so quite a few folks pointed out that in a production situation you would triage the bug (decide how important it is) and then either drop everything and fix it or roll it into the next release. Or, of course, live with it. All good stuff. But if the bug appears while you are creating a solution you have a bit of wiggle room when deciding how best to fix it. And I think you should sleep on it. As long as it won’t keep you awake…

Having left the bug and slept on it, I decided that the way the bug manifested itself reflected my poor understanding of how the program should work. To properly fix the bug I’d have to re-structure part of the code. So I did that, and the solution is much better as a result.

I’ve had this kind of experience many times. It seems that to find out how to really write a piece of code you have to write it. No amount of up-front design work shields you from this. And when you write it you must expect to have to change the structure and content of the components. I view this as a kind of battle between warring factions. As I write the code and build my understanding of what I’m trying to do I find that the objects in my solution grow and shrink. A class you think will be pivotal can shrink in importance while a “young pretender” can emerge and take over. So I don’t regard discovering bugs like this as a problem, they are part of the process. So give yourself time to deal with them properly.