Syllabus Lesson 86 of 141 · Make the bug louder
Make the bug louder

Make the bug louder

Why it matters A bug you can reproduce one time in fifty, on one laptop, cannot be fixed with confidence. A bug that fails every time, in a second, on a ten-item input, is half fixed already.

The default move with a bug is to read the code until the mistake jumps out, or to paste it into an AI assistant and ask what is wrong. Both work on small, honest bugs. On the rest, the stronger move comes first: build something that makes the bug impossible to miss, and only then change the code.

Probe: a small piece of code whose only job is to show the bug: a test, an assertion inside the code, a script that runs one input a thousand times, a log line that prints the value you are guessing about.

Four ways to turn up the volume

  • Catch more versions. A good test fails on many different wrong programs, not just the one you have.
  • Test a property, not an example. "Decoding what I encoded gives it back" holds for every input, so you can try thousands of them.
  • Shrink the input. Cut a 500-line failing file down to the 3 lines that still fail.
  • Bisect the history. If version 12 worked and version 76 does not, the first bad version is found in about six checks, not sixty-four.

The variants lessons in this module grade your test, not your fix. The course hides several broken versions of a function; your test is run against each one and against the correct one. It must pass the correct version and catch enough of the broken ones. When it misses one, the result names the area that version gets wrong, not the bug itself. This is a cut-down form of mutation testing.

Mutation testing: judging a test suite by how many deliberately broken copies of the code it catches. A suite that passes a broken copy has a hole exactly there.

Recap Before fixing, make the bug loud: a test that catches many wrong versions, a property checked on many inputs, a tiny failing input, the first bad version.

Spotted a problem in this lesson? Report it · Ask about this lesson

This exercise opens soon

Finish the lesson before it and this one unlocks. The whole course is free, no account needed, and you can read this lesson right now.