make impossible states unrepresentable
Tended 1 year ago (1 time) Planted 3 years ago Mentioned 0 times
Contents
Software not working when it’s in a bad state is the reason why “turning it off and back on again” (which resets the state to a known-good value) is the solution to so many technical issues. So how can we prevent our software from getting in a bad state in the first place? By making invalid states impossible.
- In application code, one approach to this is using types
- Prefer enums to represent state instead of multiple, possibly-conflicting columns
- In a relational database, use unique, not-null, and foreign-key constraints to prevent invalid data from even being inserted
Further Reading
- Making invalid states unrepresentable in LiveView, a talk by German Velasco at ElixirConf 2021
- An older talk, “Make Impossible States Impossible”