Skip to main content

The Debugging Method

beginner12 min readLesson 30 of 169

Reproduce, read, locate, understand, fix, verify โ€” a discipline, not luck.

Debugging is a method, not luck.

  1. Reproduce โ€” find the smallest input that triggers the bug.
  2. Read โ€” traceback? Wrong output? Start from the evidence.
  3. Locate โ€” narrow the search: does the bug exist in the input, the middle step, or the output? Print or assert along the pipeline until the region shrinks.
  4. Understand โ€” never fix what you cannot explain. "Delete this line, it seems to help" is how bugs become ghosts.
  5. Fix and verify โ€” one change at a time, then confirm the exact failure is gone AND nothing else broke.

Tools you already have

  • print(type(x), repr(x)) โ€” see the real value, not the format you assume.
  • assert condition, "message" โ€” state what MUST be true; Python checks it.
  • Explaining the code out loud (even to a rubber duck) exposes wrong assumptions.

The Bug Hunt below is this method, drilled: each broken program is a real bug pattern you will meet in your own code.

Now practice

Bug Hunt โ€” Repair Broken ProgramsFour broken programs. Diagnose, fix, verify.4 challenges ยท ยท ~45 min