5 ms·
All other things being equal, yes. Static types work well for constraints on function parameters. "Parse, don't validate" and all that. Some contracts are more
by MathMonkeyMan 1y ago
All other things being equal, yes. Static types work well for constraints on function parameters. "Parse, don't validate" and all that.
Some contracts are more difficult to express, though. The worst kind involve sequences of behavior, e.g. "start() must have been called," or "must have been obtained from a previous call to 'allocate()' on the same object."
Even value parameter constraints can be tricky. "The input must be sorted."
I haven't studied type systems, but I like the idea of values picking up attributes as they pass through functions. Imagine a "sort" function that bestows its output with the "sorted" type attribute. But then what happens when you append to that value? Is it still sorted?
At some point it's convenient to be permissive with the parameter's static type and to constrain the caller with a contract.