BeginnerTopic 11 of 104Software & Computing
Debugging
Systematically locate and fix defects using prints, debuggers and tests.
In depth
Debugging finds and fixes defects: reproduce, isolate, hypothesise, test, fix, verify. Tools: print/logging, debuggers with breakpoints and watches, assertions, unit tests, bisecting commits, profilers. Read error messages and stack traces carefully; explain the bug to a rubber duck.
Key points
- Scientific method
- Minimal reproducible example
- Regression tests
ExampleA stack trace points to the line where a null reference occurred.
What is Debugging?
Systematically locate and fix defects using prints, debuggers and tests.
Why is it important to understand debugging?
Debugging is a large part of programming work, so a systematic method saves far more time than guessing.
What is the first step when a program misbehaves?
Reproduce the problem with a minimal input, then narrow down where the values first go wrong.
Are print statements enough?
They help for simple problems, but a debugger, unit tests and logging are better for complex or intermittent bugs.
How is Debugging used in practice?
Typical applications include finding why a loop gives the wrong total, tracking down a crash that happens only with certain input and checking why a function returns null in one case.
What should I learn before Debugging?
Study "Recursion" first (topic 10 of 104 in Software & Computing). It covers the groundwork this topic builds on.
What are the key points of Debugging?
Scientific method. Minimal reproducible example. Regression tests.
Can you give an example of Debugging?
A stack trace points to the line where a null reference occurred.
What comes after Debugging?
The next topic is "Pseudocode and flowcharts", which builds directly on this one.
How difficult is Debugging?
It is classed as Beginner in Software & Computing (topic 11 of 104). It is an entry-level topic. It relies only on basic school mathematics and the ideas introduced earlier in this discipline.