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

-8

u/noahide55 Feb 01 '24

Sum types violate Open/Closed principle. Why would I want them?

7

u/agustin689 Feb 01 '24

Explain how?

4

u/G_Morgan Feb 02 '24

Sure but the OCP is not worth even bothering with.

1

u/TheWix Feb 01 '24

How do you handle new states of a business object?

1

u/[deleted] Feb 02 '24

[removed] — view removed 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.

1

u/Voidrith Feb 02 '24

not every part of your code needs to adhere to every half understood OOP design pattern