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.
- Reproduce โ find the smallest input that triggers the bug.
- Read โ traceback? Wrong output? Start from the evidence.
- 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.
- Understand โ never fix what you cannot explain. "Delete this line, it seems to help" is how bugs become ghosts.
- 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.