5 steps of debugging

  1. Understand the context
    If you are confronted with a bug, you first have to understand the circumstances. What is the software/system supposed to do? What was the idea of the developer(s)? The more you understand, the better. That’s why its also easier to debug you own code. But for foreign code don’t want to waste too much time, rather you will assume certain things. That brings us to point 2:
  2. Verify your assumptions
    While understanding a system, you will also assume certain things. For example if you see a “getSomething” method, you most likely assume that it just returns an existing value. Verify that. I’ve seen many cases where a method does not what it says.
    It’s also likely that the system works as expected and you just forgot to check the system configuration. I already experienced hours of debugging after finding a simple setting that was just there with an unexpected value.
  3. Check the logs
    I already wrote about it: logs have the power to reveal internal state and quickly lead you into the right direction. At least they help you to understand the context better.
    Of course its sometimes hard to find the proper logs or sometimes there are none. If you have the ability to add logs to some silent but potentially problematic code, then do that. In the early PHP days this is how we did debugging: an “echo” every 5 lines printing variables. :D
  4. Check the input data
    What has an impact on how the system works? Besides Parameters and Configs there is the data itself. Verify that it is properly formatted and accessible. In the age of Unicode it may still happen, that some ISO formatted file or some strange line-brakes break the system.
    But also the content of the files could have unexpected data.
  5. Reproduce with minimal setup
    If nothing helps, try to reproduce the bug in a smaller setup. That’s especially true for coding bugs that are hard to reproduce in the productive system. Try to build a small test case that leads to the same error. Due to a smaller setup, the debugging is easier.

Still lost? Well, sometimes you have to dig through the whole mud to fix things. ;)

Most likely those 5 steps are not complete. If you have some more standard steps to go during debugging, let me know in the comments.

Leave a comment