Jumping out of the Loop

One psychological factor responsible for producing bugs and preventing their detection is an inability to jump from one mind-set to another. For example, in our push to examine what are often subtle details, we often overlook the obvious. The results of a study performed a decade ago showed that that 50 percent of all errors plainly visible on a screen or report were still overlooked by the programmer. The kind of mistake shown in the preceding sentence (“that” repeated) seems fairly obvious in retrospect, but did you spot it the first time through?

One reason for this tendency to overlook the obvious is that the mind-set required to find gross errors is so different from the mind-set needed to locate subtle errors that it is hard to switch between the two. We’ve all been in the situation in which the cause of a bug has eluded us for hours, but as soon as we explained the problem to another programmer, the cause of the error immediately became obvious. In this type of confessional programming, the other developer often doesn’t even have to say a single word, just nod wisely. The mental switch from an internal monologue to an external one is often all that we need to force us into a different mind-set, and we can then reevaluate our assumptions about what is happening in the code. Like one of those infuriating magic pictograms, the change of focus means that what was hidden before suddenly becomes clear.

Some Final Thoughts If you’re stuck on a particularly nasty bug, try some lateral thinking. Use confessional programming, explaining the problem to a colleague. Perhaps take a walk to get some fresh air. Work on something entirely different for a few minutes, returning later with a mind that’s fresh to the problem. Or you can go so far as to picture yourself jumping out of that mental loop, reaching a different level of thought. All of these techniques can help you avoid endlessly traveling around the same mental pathways.