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
- A BST with one misplaced node still returns answers. When does anybody notice?
- 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.
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
- Order the steps of debugging a data structure with an invariant checker.
- An invariant checker is written, run during development, and deleted before release. What was gained, and…
- Sort each statement about a binary search tree by whether it is an invariant of the structure.
- Select every benefit the lesson attributes to writing an invariant checker.