Sunday, November 12, 2006

Debugging skills -- It's not Rocket Science!

Every programmer knows all too well that there will be times when (non-trivial) code does odd things. Yes, I am talking about bugs. Often times they are simple because they easily reproducible and the faulty behavior can be seen in a simplified environment. But what if the bug is not easily reproducible. That's where good debugging skills come to play.

Sometimes debugging feels like detective work but in almost all cases it really isn't much more than breaking a big problem into many smaller problems. Yes, simply breaking an input down to smaller pieces until a problem disappears is often a good way of making one's life a lot easier. Besides having a good grasp of eliminating possibilities, a decent knowledge of debugging techniques and tools is certainly helpful. On my last project, more than once I was asked to help fix some bugs by other developers. When I asked them what they have tried so far or found out they usually said nothing. They just needed help. My first thought was that it was laziness. ASking someone else to fix a problem is certainly easier than fixing it yourself. But after interacting with them it dawned on me that they often had no idea of how to get a handle on the problem. Just asking questions about how and when the problem presents itself are often not asked. Well, bugs never come with a manual on how to fix them so you better ask questions if you want to fix them.

Another helpful aspect for debugging is to know the code itself. A lot of times I have found that developers didn't even know how to debug their own code. Having a good knowledge of the structure of the code helps to eliminate potential sources of errors. I can't claim for myself that I am the world's best debugger nor do I want to do that. But I was surprised how few people actually can debug and provide useful information when helping to find fix a bug. Makes you wonder if the CS curriculum should be extended by a mandatory class: "Introduction to Debugging"

It's not rocket science -- like so many other things applying common sense and using the good ol' divide and conquer technique helps a good deal.

No comments: