LLearnCode
Academy/production/Debugging discipline

intermediate · 23 minute study

Make one hypothesis face a counterexample

Changing several things until a bug disappears can leave you unable to explain the fix or prevent the failure from returning.

Loading progressEvidence grows with practice
Useful preparation · 1 prerequisite

Use this as a map, not a lock. If these ideas are familiar, continue.

First, build a mental model

A hypothesis earns confidence by making a prediction that could be wrong. A regression test preserves the smallest counterexample after the fix.

  1. Write competing explanations and choose a cheap experiment whose outcomes distinguish them. Repeating the same successful case adds little evidence.
  2. Change the mechanism responsible for the contract failure. Avoid masking the symptom with broad catches, disabled validation or ignored errors.
  3. Keep the original failing case and a nearby valid case. A fix that rejects every input can pass a rejection test while breaking the feature.
  4. A regression test should fail against the defective behavior and pass against the corrected behavior for the intended reason.
Read the codejavascript · educational example
function parseCount(raw) {
  const count = Number(raw);
  if (!Number.isSafeInteger(count) || count < 0) {
    throw new Error('Count must be a nonnegative integer');
  }
  return count;
}
// Critic's question: should '' really mean zero?
  1. Hypothesis

    Numeric conversion alone may accept inputs the product considers missing.

  2. Counterexample

    Number('') is 0. The shown function accepts a blank string.

  3. Repair contract

    Decide whether blank input is invalid, then reject it explicitly before conversion and retain valid numeric input.

Production thinking

Take this beyond the example.

Stop widening the patch once the actual invariant is restored and its regression is covered. If the contract itself is ambiguous, resolve that decision rather than inventing an expected value.

Sources and further reading

Your evidence

unseen is a local learning signal, not a credential or proof of production competence.

Explain the mental model, then explicitly acknowledge it. Opening a page is not evidence.

Supported retries can complete this lesson. Independent evidence and delayed review determine the skill stage.

Next lesson · Choose the test that can actually prove the claim →