Phase 5: Debugging Methodology · ~30 minutes · Python · print debugging · logging
The Cheapest Tool First
A single well-placed print statement finds most bugs faster than launching a debugger. Reach for the expensive tool because you measured a need for it, not out of habit.
Real-world application: Escalates debugging tools deliberately, starting cheap, instead of reaching for the heaviest tool out of habit
What you will learn
- Explain the real escalation ladder: print/logging first, interactive debuggers next, specialized tracing last
- Diagnose a bug using only print/logging before reaching for anything heavier
- Recognize when a bug's subtlety genuinely warrants a more sophisticated tool
- Choose the cheapest appropriate tool for a given bug description
Introduction
- Type: Learn
- Languages: Python
- Prerequisites: Databases & SQL for AI/ML
- Time: ~30 minutes
Objective
Learning objectives
- Explain the real escalation ladder: print/logging first, interactive debuggers next, specialized tracing last
- Diagnose a bug using only print/logging before reaching for anything heavier
- Recognize when a bug's subtlety genuinely warrants a more sophisticated tool
- Choose the cheapest appropriate tool for a given bug description
What you'll do
The lab puts this lesson's three bugs in an editor on the lab page. There is nothing to install.
- Find the first (obvious) bug with one print statement, and fix it.
- Find the second (input-dependent) bug by printing results across a range of inputs that includes the boundary value, and fix it.
- Find the third (subtle, state-related) bug by tracing what
checkout() sees across two calls, with prints or id(), and fix it.
You're done when every check on the lab page passes and you can say, for each bug, why the tool you used was cheap enough.
A function produces a wrong result, and you can already tell exactly which line is wrong just by reading the function — it's short, and the bug is a single misplaced operator. What's the appropriate first tool?
This describes exactly this lesson's Bug 1 pattern: a short function, a bug already visible on inspection. The cheapest tool — a print statement confirming the actual vs. expected value, or simply reading the one-line function carefully — resolves this immediately. Reaching for a debugger or profiler here adds real setup time to a diagnosis that's already complete, which is precisely the discipline this lesson is building: match the tool to the bug's actual subtlety, escalating only when the cheaper tool has genuinely stopped being enough.
This lesson is free
You've read the first 2 sections. The rest covers The Problem, Check Yourself, Key Terms & Next. A free account opens all of it, with its practice questions and its lab. No card.
Create a free account — the opening phases of 29 of 35 courses, and the first lesson of every phase, are free, no credit card.
Browse all courses · View pricing · DeVenture Academy