Comment by qtplatypus
6 years ago
I agree broadly with this however in many cases that I have been dealing with I don't think that there can be a type system that would be rich enough to encode the validation laws.
For example how would you encode "This purchase request must be made before the closing date for the purchase"?
This isn't about encoding the validation rules in the type system, only the requirement that validation with respect to some properties has been done. So in your example you would just define a function
now everywhere in the code taking a PurchaseRequest can assume it is valid.
This sounds like the Nirvana fallacy. Just because parsing over validation is not perfect, it can still lead to significantly more maintainable code and safer and stabler system.
Pure validation has a lot of problems, namely that you have to validate the data on all levels for the invariants required at that level.