How to use a debugger instead of print statements
Printing values works, but a debugger lets you pause a program and look around while it's running. Learning the basics is one of the best upgrades for a beginner.
Core concepts
- Breakpoint: a marker on a line where execution pauses. Most editors let you click in the margin to set one.
- Step over: run the current line and move to the next.
- Step into: go inside the function called on the current line.
- Step out: finish the current function and return to the caller.
- Continue: run until the next breakpoint.
- Variables / watch panel: see current values, and add expressions to track.
- Call stack: shows which functions led to the current line.
A simple workflow
- Reproduce the bug and guess roughly where it goes wrong.
- Set a breakpoint a bit before that point.
- Start the program in debug mode.
- Inspect variables when it pauses. Are they what you expected?
- Step forward line by line until a value goes wrong.
Useful extras
- Conditional breakpoints pause only when a condition is true, like
i == 500. - Logpoints print a message without editing code.
- Breaking on exceptions pauses exactly where an error is thrown.
When print statements are still fine
Quick checks, code running on remote servers, or timing-sensitive issues where pausing changes the behavior.
Do you use a debugger regularly, or mostly print? What feature made you switch?
Comments · 4
Conditional breakpoints are the superpower people miss. Pause only when the value is wrong instead of stepping through a loop a thousand times.
Print statements are like duct tape: ugly, but they hold. I'll switch to a debugger the moment my duct tape runs out.
Do you recommend learning the debugger in your editor or the language's command-line one first?
Start with the editor's debugger since the UI shows variables and the call stack. Learn the command-line one later for servers and quick checks.