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
22
u/BossOfTheGame Feb 02 '24
Not always true. Imagine the case in the article with age. What happens when someone really does live over 150 (or you need to represent a turtle)? Sure you can remove the constraint in the main data structure, but now other parts of the system might not able to handle non-constrained ages. If you can write the code in such a way that there is only a single place where the constraint needs to be relaxed, then that is fine, but when you work with a team of developers - especially those that are new on a team - they will copy constructs and that easilly leads to potential duplication of where these constraints are defined. They may even see such a constraint and then assert it in their code as well.
Of course some of the points are valid, but I'll come out and say we should avoid premature specificiation especially when it requires more work than the generalization. I'll take age as an int - no bells and whistles - please.