Practice question · Put in order
Order the steps of the disciplined debugging routine.
- Understand why that line produces the wrong value
- Reproduce the bug with an input that triggers it every time
- Fix the code and re-run the reproducing case and the rest of the suite
- Halve the region between a good point and a bad one, repeatedly
Hints
- A bug you cannot reproduce, you cannot reliably fix.
- Understanding the cause comes before changing the code, not after.
Show the answer
- Reproduce the bug with an input that triggers it every time
- Halve the region between a good point and a bad one, repeatedly
- Understand why that line produces the wrong value
- Fix the code and re-run the reproducing case and the rest of the suite
Why
Reproduce, localize, understand, then fix and verify. Reproducing first is essential: without a reliable trigger you cannot tell whether a later change actually fixed anything. Fixing before understanding is 'shotgun debugging', the pitfall this lesson names.
Practise Debugging Logic and State
The app has 6 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.
More questions on Debugging Logic and State
- A bug appears only in production, never locally, and disappears when logging is added. What class of bug does…
- Select every practice that the lesson recommends for debugging.
- Systematic debugging narrows down where the state first becomes wrong, rather than reading the code looking…
- Sort each debugging action by whether it reasons from evidence or merely guesses.