Pillar Two: Localizing Invariants

#56 - Refactoring–The Discipline for Writing Good Code - Christian Clausen

Topic 9 of 18

Published Sep 20, 2021 · Clip 23:50–24:54 (1:04)

Christian defines an invariant as something true about the system that the system itself doesn't enforce — something you must keep in your head. When two places rely on the same unchecked invariant, breaking it in one place affects the other. Invariants should therefore have the smallest scope possible, e.g., true only within one method you can fully see, rather than global fields anyone can corrupt.