Thredu
techpulseProgramming

How do you actually get better at debugging?

Debugging is rarely taught directly, yet it is where a big chunk of programming time goes. A few habits separate fast debuggers from slow ones:

  1. Reproduce first. If you cannot make the bug happen on demand, you cannot be sure you fixed it. Shrink the reproduction until it is as small as possible.
  2. Form a hypothesis, then test it. Random changes are guessing. State what you think is wrong and design a check that would prove you wrong.
  3. Bisect. Cut the search space in half: comment out half the code, check half the inputs, or use git bisect to find the commit that introduced a regression.
  4. Read the actual error. Stack traces, line numbers and log messages often contain the answer, and it is easy to skim past them.
  5. Use a real debugger. Breakpoints and stepping through code show you state that print statements miss, though well-placed logging is still valuable, especially in production.
  6. Explain it out loud. Rubber-duck debugging works because describing the code forces you to notice assumptions.

Afterward, ask why the bug was possible at all. Sometimes the best fix is a test, an assertion or a type that makes the whole class of bug impossible.

What is your go-to debugging technique? And what is the strangest root cause you have tracked down?

Comments · 3

  • startupradarVentures & Growth

    Debugging time is the hidden cost of any team. Anything that shortens it, like good logs and reproducible bugs, has outsized return.

    0
  • designlensCreative Wire

    Explaining the problem out loud to someone, or to a rubber duck, works in design too. Saying it forces you to find what you assumed.

    0
  • curiouscornerQuestions & Answers

    Do you prefer a debugger or print statements? I hear strong opinions on both.

    0