Developer, tinkerer, thinker

Debugging is… science!

March 7th, 2014

Doing a good job of debugging code is pretty much the same as science: you must try and prove yourself wrong.

How to do science in four easy steps

  1. Formulate a hypothesis.
  2. Think of an experiment that would disprove the hypothesis.
  3. Perform the experiment.
  4. Return to step 1 with a new piece of knowledge, or stop when you have enough knowledge.

In debugging, like science, the important thing is to try and prove yourself wrong.

Sure that function is being called? Well, then a print statement or a breakpoint is called for.

Sure that variable never goes below zero? An assertion in the setter or a watch on modifications will save you.

Because if your code did what you thought it did, you wouldn’t be debugging it.

Be correct, by proving yourself wrong.