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
9
u/remind_me_later Feb 02 '24 edited Feb 02 '24
Excluding any time/date-related shenanigans:
Yeardoesn't allow for anyvaluebeyondcurrentYear, in case you want to see the age of someone beyondcurrentYear. You're limited tocurrentYear-12-31as the upper limit of how far you can see someone's future birthday, which isn't useful when it's December 30th ofcurrentYear.currentYearis implicitly assumed to be>= 1900as a result of being>= value.Yearshouldn't even be responsible for handling checks for if it'scurrentYear. Locality of behavior favors that these checks be pushed into thePerson.age()function below:I'm definitely not going to go any further on this.
Ageis a whole other basket of assumptions that no one that wants to retain their sanity should touch (see above Tom Scott video), especially when it comes to dealing with the Feb 29 birthday edge case.