Course outline · 0% complete

0/29 lessons0%

Course overview →

Debug Like a Scientist

lesson 7-1 · ~9 min · 20/29

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:

  1. Observe the symptom precisely. Not "it's broken" but "total is 6 when 5.0 was expected, for even-length input"
  2. Hypothesize one specific cause: "the median picks the wrong index when the list length is even"
  3. Predict something checkable: "then median([1, 2]) should return 2, not 1.5"
  4. Experiment: run exactly that check
  5. 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.

observethe exact symptomhypothesizeone specific causeexperimenttest the predictionconcludefix, or loop againthe gold dot is you, going around until the hypothesis survives
The hypothesis-driven debugging loop. Each lap changes exactly one thing and learns exactly one fact.

Quiz

Your hypothesis was "the discount is applied twice" but the experiment shows it is applied once. What did the loop just buy you?