Quiz
Warm-up from lesson 6-2: all unit tests pass but the assembled program crashes at the seam between two components. Which kind of test was missing?
Guessing is not a method
Sooner or later a bug arrives that no test predicted. Beginners debug by vibes: change something, run, change something else, run, until the error goes away and nobody knows why. That wastes hours and often buries the bug instead of fixing it.
Professionals run a hypothesis loop, the scientific method pointed at code:
- Observe the symptom precisely. Not "it's broken" but "total is 6 when 5.0 was expected, for even-length input"
- Hypothesize one specific cause: "the median picks the wrong index when the list length is even"
- Predict something checkable: "then median([1, 2]) should return 2, not 1.5"
- Experiment: run exactly that check
- Confirmed? Fix it, and add the regression test from lesson 4-3. Refuted? Back to step 2 with what you learned
One rule makes the loop honest: change one thing per experiment. Change two and you cannot tell which one mattered.
Quiz
Your hypothesis was "the discount is applied twice" but the experiment shows it is applied once. What did the loop just buy you?