Saltar al contenido ForoHackers

Debugging: start here

Depuración
#3353 · · Citar · 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

No has iniciado sesión, así que esto se publica como anónimo: no se guarda con ello ninguna cuenta, nombre ni dirección, y no puede llevar enlaces ni imágenes. Inicia sesión o únete para publicar con tu nombre. Los registros de nuestro servidor web guardan la dirección y la hora de cada petición hasta 14 días; para que la tuya no quede en ellos, usa Tor. Para escribir al equipo de forma confidencial, usa el buzón. Firmar como fuente habitual (una clave guardada solo en este navegador)

Enviar tarda unos segundos aquí: tu navegador resuelve antes una prueba de trabajo contra el spam.

Responder