Skip to Content

Tips for Debugging: When One of Your Assumptions is Wrong

[Web Development, Community]
Debugging code is part of a programmer's daily life that is essential, but requires a fine-tuned set of skills that constantly evolves. Especially early on in a programmer's career, it is common that assistance from a senior may be required to solve an issue and keep a project going. But as software engineer and blogger, Amir Rachum, points out, there is a way to go about debugging your code whilst collaborating in this task that can help to expedite the process and prevent incorrect assumptions from clouding others' judgement. Amir reminds us of the all-too-familiar stages of debugging:
  1. That can’t happen.
  2. That doesn’t happen on my machine.
  3. That shouldn’t happen.
  4. Why is that happening?
  5. Oh, I see.
  6. How did that ever work?
And he points out that the key to solving the problem happens between the third and fourth stages:
"The first three stages are a mixture of denial and self delusion. This transition is the understanding that one of your assumptions is wrong. It is the acceptance that in the battle between reality and our thoughts, reality wins."
So, if there is a fundamental problem with one of our assumptions we need to be aware that we are capable of passing along these misinformed opinions to those we collaborate when we present them with our bugs. In doing this, we may lead them down the same incorrect paths we have already traveled ourselves and distract them from their own analytical processes that could more efficiently bring you to the correct solution. This is why Amir emphasizes the importance of:
"...try[ing] to be consciously aware to not infect the other person before they get to see the behavior themselves. Even after that, I try to minimize the perceived correctness of my previous efforts to solve this bug. I try to phrase myself in non-conclusive ways."
We hope this simple, yet insightful advice may bring you some new ideas when debugging your code and help you to maximize the results of collaborating with your team. To read Amir's full article, check it out here. Happy programming!