4 ms·
Agree. I try hard to push the validation to static checks, but it can't always be done. For example: - a "probability" represented as a double must always be
by afc 2y ago
Agree.
I try hard to push the validation to static checks, but it can't always be done. For example:
- a "probability" represented as a double must always be between 0 and 1
- A vector of values given to some group of functions must always be sorted (by some given order)
But even in those cases, using types allows me to ensure that this validation always happens (when the type instance is created). It also let's me avoid having to explicitly validate this inefficiently (e.g. redundantly in preconditions in functions that receive these values).
This doesn't change the fact that static validation is a better approach, but compliments it.
I wrote a bit about it here: https://github.com/alefore/weblog/blob/master/edge/correctness.md#ghost-types-validators https://github.com/alefore/weblog/blob/master/edge/correctne...