Invariants are cheap. Silent corruption is not.
We had five numbers that were supposed to add up. Nothing in the codebase checked that they did. The relationship nobody wrote down A tracked journey produces five distance figures: original , cleaned , mock , abnormal and spike . Anyone on the team could tell you how they relate: cleaned = original - (mock + abnormal) With one wrinkle. spike is not in that equation, because spike distance is…
The article "Invariants are cheap. Silent corruption is not" discusses an issue with code that tracks various distance metrics during a journey. The code lacks a check that certain calculated values add up correctly, which is an invariant. The author argues that while a refactoring could potentially break this invariant, a reasonable engineer could fix it.
The article then introduces a validation function that checks for errors in the distance metrics, including warnings for unusual ratios and large discrepancies. These checks are designed to catch issues that the invariant alone cannot identify. The author emphasizes the cost-effectiveness of these checks, stating that the entire validator is only around eighty lines of code and runs quickly.
The takeaway is that while invariants are important for catching bugs, additional checks are necessary to ensure the accuracy of the classification system.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.