Knowing And Debugging

Posted on May 4th, 2012
Categories: programming, ruby

There’s nothing I like better than a good science news story. You know the sort of thing: Extinct Monkey Found Alive and Well or Scientists Discover Galaxies Far, Far, FAR Away (Who would have thought?). So it should come as no surprise that I was thrilled right out of my geeky little shoes over the whole faster-than-light neutrinos thing You can read about it here in case you have been living in a cave. Better still, I have a friend who is a physicist, so when I saw him recently I jumped at the chance to hear what he had to say about those quicker than quick neutrinos. Here is what he said:



Not only that, but he also added:



The fact is that beyond acknowledging that the experiment had been done and the results published, I couldn’t get my buddy to weigh in one way or the other about those speedy neutrinos. Not one word.

Suspension of Any Belief

If you think about it, my friend’s closed mouth attitude is easy to understand. He is a physicist, someone who is paid to pry out the secrets of the universe one tiny teaspoon at a time. It’s hard, painstaking work and the worst thing that you can do is to get ahead of the evidence. When you are working at the very edge of understanding then keeping track of what you really know and what you only suspect is the only thing that will keep you from stepping off the intellectual cliff.

Fortunately building software is usually an easier proposition than measuring the speed of very fast neutrinos to the seventh decimal point. We usually have at least a vague idea of what we are building and a decent idea of how we are going to build it. Except when we are debugging. Now I’m not talking about noticing an obvious bug and squashing it in the few minutes that it takes to find the right line of code. Nor am I talking about the kind of debugging where you sit there puzzled for ten minutes and then sit up and say “Ah Ha! Off by one!.” No, I’m talking about those occasions where you stare at the screen for hour after hour, muttering things like “What the heck?” You feel like you understand what’s going on, you can see nothing wrong with the code, you have checked the test data, and yet, well the program continues to do things that it shouldn’t ought to be doing.

It’s Either You Or Mother Nature Who Is Wrong

When you come to those moments the best strategy is to go into full physicist mode. What exactly do you know? Not what do you think, surmise or guess. What do you know? The times when nothing is making sense are the times to put aside all interpretation, all intuition, and to ignore the whispers of that little angel or devil sitting on your shoulder. What do you know? In my own debugging adventures I’ve lost count of the number of times I’ve told myself, “Well it can’t be X” and also “It can’t be not X”. That’s the moment when you want to pause for a bit and think things through: The problem is either X or it is not X. Or perhaps X doesn’t figure into it at all and you just don’t know what you’re talking about. So what do you really know?

Frequently the problem is that you don’t know enough. Perhaps you are just assuming that the file gets written or the layers are rendered in the right order or the connection to the database is failing. Well get out your physicist approved crowbar and start prying out facts. It is amazing the number of hours that programmers spend just staring at the code, trying to puzzle it all out, when two print statements or a trip to the debugger is all you need to know for sure. Look at it this way: You already know what you think. But if you are stuck, what you think is clearly somehow at odds with the laws of the universe, plus or minus fast neutrinos. Why not let the universe - in the form of what the code is actually doing - have some input into your thinking?

Science - and debugging - is littered with the professional bodies of people who jumped just a little too hard to reach a conclusion. We could all use my physicist friend as a role model: Know what you know and what you only think. When in doubt gather more facts. When not in doubt, gather facts anyway.

Oh and those fast neutrinos? Well the jury is still out, but it’s looking more and more like the speed of light isn’t just a good idea, it’s the law.

Russ

comments powered by Disqus