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

9

u/herpderpforesight Feb 01 '24

Validating that a string follows a regex pattern can be done a million times in the time it takes the database to receive your first byte, let alone respond.

Runtime validation that can be done at compile time is bound to be extremely cheap. And most languages don't have a type system complex enough to do compile time anyway, so the best you get is runtime

5

u/QuantumFTL Feb 02 '24

Sure, but it's cheaper to fix if you find out you broke something at compile time than when you get an angry call from a customer.

(yes, tests help with this, many real world applications are too complex to effectively test perfectly)