Scientific method & Debugging

Scientific method

The scientific method is often represented as an ongoing process.

© Robert Sedgewick and Kevin Wayne

  • Observe some feature of the natural world, generally with precise measurements.
  • Hypothesize a model that is consistent with the observations.
  • Predict events using the hypothesis.
  • Verify the predictions by making further observations.
  • Validate by repeating until the hypothesis and observations agree.

One of the key tenets of the scientific method is that the experiments we design must be reproducible, so that others can convince themselves of the validity of the hypothesis. Hypotheses must also be falsifiable, so that we can know for sure when a given hypothesis is wrong (and thus needs revision). As Einstein famously is reported to have said (“No amount of experimentation can ever prove me right; a single experiment can prove me wrong”), we can never know for sure that any hypothesis is absolutely correct; we can only validate that it is consistent with our observations.

Scientific Debugging

  1. Observe. we look at the behavior of the program. What are its outputs? What information is it displaying? How is it responding to user input?
  2. Hypothesize. we try to divide the set of possible causes into multiple independent groups. For example, in a client/server app, a potential hypothesis might be “the bug is in the client”, which is either true or false; if false, then presumably the bug is on the server. A good hypothesis should be falsifiable, which means that you ought to be able to invent some test which can disprove the proposition.
  3. Experiment. we run the test — that is, we execute the program in a way that allows us to either verify or invalidate the hypothesis. In many cases, this will involve writing additional code that is not a normal part of the program; you can think of this code as your “experimental apparatus”.
  4. we go back to the Observe step to gather the results of running the experiment.