Debugging software using the scientific method
Debugging is the process finding and resolving of defects that prevent correct operation of computer software or a system.
It can be very hard sometimes and eventually you might end up going around in circles and spend a lot of time until you find what’s causing the you’re investigating. When I find myself stuck in this loops one tool that helps me is to keep track by handwriting the investigation process following the scientific method.
According to wikipedia “The scientific method is a body of techniques for investigating phenomena, acquiring new knowledge, or correcting and integrating previous knowledge.”[1]. It has some steps that you can follow: Ask a Question, Construct a Hypothesis, Test with an experiment, Analyze data and Draw conclusions[2].
In each of the steps you should be writing down what you did in a succinct manner so you can come back at your notes at any time. The notes have succinct, you should spend your time thinking about the issue not writing.
Ask a Question
The question could be:
— What are the symptoms can I spot?
— Have I seen something similar before?
— What part of the system might be causing the problem? Infrastructure, Hardware (RAM), OS, Network, Code ?
Construct a hypothesis
Make a statement of something that you believe that might be causing the problem (with or without evidence for it).
Test with an experiment
There are many ways, at different levels, that you could figure out experimenting what could be causing a problem. The most common ways are:
- Ask the person that the problem is occurring to do it in front of you.
- Try to run manually the code/application that is having the problem.
- Try to put the code in a test harness.
- Put logging around the conditions that might cause the problem and wait until it occurs in production.
Analyse the data
After you run the experiment you either successfully reproduced the problem or not. In case you weren’t successful you’d go through the whole process again. It’s important to take notes, because you might be interrupted or have to walk away from the problem (end of the day, end of week). The notes will help you to not loose context and not do the same thing twice.
The other benefits of having the notes are: easy to make a report if you need to explain someone what’ve you tried, you’d have it in all the notes.
Conclusion
Once you found how to reproduce the issue it’s time to think about what can you do to solve the issue. It might be tempting to go with the quick fix (and sometimes the quick fix will do), but I recommend doing root cause analysis [3].
When/How to use this method
For some issues it might be an overkill to have to write down all the steps but for others it pays off to have it documented. You have to find the balance your own but I strongly recommend time-boxing (doing it for a limited amount of time, like half an hour) your time without following a process, and then use the process.
[1] https://en.wikipedia.org/wiki/Scientific_method
[2] http://www.sciencebuddies.org/science-fair-projects/project_scientific_method.shtml
