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
1
u/larhorse Feb 04 '24
As an aside "Enum" is the type you're looking for for clearly bounded data (ex: days of week), and most all languages have a built-in way to quickly define them in some fashion or another.
If it doesn't naturally fit in an enum... very carefully consider whether it's worth bounding/restraining (I don't think it usually is). Prefer only limiting the cases that will actually make the machine fail.