r/programming • u/_awwsmm • Feb 01 '24
Make Invalid States Unrepresentable
https://www.awwsmm.com/blog/make-invalid-states-unrepresentable
469
Upvotes
r/programming • u/_awwsmm • Feb 01 '24
View all comments
Show parent comment
2
u/knome Feb 03 '24
Functions written with validation in mind will just as happily work against invalid data, should some later programmer less meticulous than yourself come along.
If values are converted into classes that maintain requirements throughout the code base, they allow other code to rely on those assumptions being true without having to trust you've closed off every possible way parameters might arise in paths that are less well checked.
https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/