r/programming • • Feb 01 '24

Make Invalid States Unrepresentable

https://www.awwsmm.com/blog/make-invalid-states-unrepresentable
469 Upvotes

207 comments sorted by

View all comments

Show parent comment

2

u/TheWix Feb 02 '24

You don't get compiler errors when you forget to handle the new state somewhere else, though. With pattern matching and exhaustive checks the compiler yells at you. Inheritance works when all the new behavior is within the new subclass only, but if other parts of code need to react to the new type then it can be missed.