Saltar al contenido ForoHackers

Debugging: start here

Depuración
#847 · Ophuscado · · Denunciar

Debugging is finding why a program does something other than what you meant, and fixing the cause rather than the symptom. It is a method, not luck: observe, form a hypothesis, test it, repeat. Programmers spend more time here than writing new code, so the skill pays back every day.

Key concepts

  • Reproduce first: a bug you can trigger on demand is half solved; shrink it to the smallest failing case.
  • Hypothesis and experiment: change one thing at a time and predict the result before you run it.
  • Bisection: halve the search space, over code, inputs or commits, until the culprit is alone.
  • Observation tools: debugger, logs, assertions, core dumps and tracing show state without guessing.
  • Root cause: ask why until the answer is a design flaw, then add a test that would have caught it.

Vocabulary

  • Breakpoint: a place where the debugger pauses the program.
  • Stack trace: the chain of calls that led to the current point.
  • Heisenbug: a bug that changes or vanishes when you observe it.
  • Regression: something that worked and no longer does.

What to study, in order

  1. Use a debugger on a small program: breakpoints, stepping, inspecting variables and the call stack.
  2. Read stack traces and error messages completely, from the first line, before searching.
  3. Practise bisection with your version control tool on a regression.
  4. Learn memory and thread debugging tools for your language, such as sanitizers and race detectors.
  5. Explain a bug aloud to someone, or to a rubber duck, before changing any code.

Related tags

#testing #observability #version-control #performance

Inicia sesión o únete para responder.