Computer Science I / Debugging Structural Invariants
Practice question · Multiple choice

An invariant checker is code that verifies a structure's rules and is never called in production. Why is writing code you intend not to ship worth the effort?

Hints
  1. A BST with one misplaced node still returns answers. When does anybody notice?
  2. Ask what it costs to debug a failure that surfaces far from its cause.
Show the answer

C. Because it converts a distant symptom into an immediate one.

Why

The value is in the distance between cause and symptom: a BST with one node on the wrong side does not crash, it quietly fails to find a present value thousands of operations later, in code that did nothing wrong. A checker turns that into an immediate local failure. It must detect and shout rather than repair, a checker that fixes what it finds destroys the evidence and leaves the bug.

Read the lesson: Debugging Structural Invariants →

Practise Debugging Structural Invariants

The app has 6 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.

More questions on Debugging Structural Invariants