Thursday, April 5, 2007

Fair Witness

In the book Stranger In a Strange Land, Robert Heinlein introduces the concept of a Fair Witness. In the book a Fair Witness is someone with complete memory recall (they remember EVERYTHING!) who makes no assumptions about anything. They're used for various legal things because they are infallible observers.

There's a quote from the book which I always liked. I can't remember it exactly but it goes something like:
"Anne, function as a Fair Witness! What color is that house over there?"
"This side is blue."
Obviously the other sides could be any color at all. But it wouldn't occur to you to think that way, and in most cases it wouldn't make sense to.

However, attempting to assume this kind of mind set can be enormously helpful for a software developer. How many times have you been tracking down a bug for hours and hours and hours, unable to figure out what's causing it. "Everything looks right!" you keep saying to yourself. Finally you discover the problem: you had made an assumption about some part of your code that turned out not to be true.

Sometimes its an assumption that you programmed into the code that turns out to be false. These are usually easier to find. Other times its an assumption you made in your mind about the behavior of the code. Could be, "I know this method is working fine" or "It will never do xyz because of abc." Then when you find the bug you realize that not only was your code wrong but you were wrong too. It was two bugs in one.

Of course, being human we can't avoid making assumptions. Assumptions are powerful for the same reason abstraction in Object Oriented Programming is powerful. It lets you forget about the details and focus on a higher level idea. But in my limited experience I've noticed that being human also comes with a tendency to want to rush. And nothing helps you rush more than making assumptions. So now when I set out to find a bug I always remind myself to function as a Fair Witness. I'll still make incorrect assumptions from time to time, but I'll avoid making a countless number of rush-assumptions. And ultimately, I'll end up saving myself time and frustration.

That being said, making assumptions in debugging can be a good thing too. You just have to make your assumptions in a very conscious manor. As in, this side of the house is blue, so I'm going to assume the other sides are as well. Then if you run into an inconsistency later on you'll remember you made the assumption and you can go back and examine if it was the right one. The author of The Old New Thing blog calls this Psychic debugging. I call it functioning as a more flexible Fair Witness.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.