On Mon, Oct 1, 2018, 9:13 PM Steven D'Aprano firstname.lastname@example.org wrote:
For an application, it doesn't matter if my function sets the computer on fire when passed the string "fish", if there is no way for the application to pass that string to the function. If it can't happen, it can't happen and there's no need to defend against it beyond a regression test.
How many times have you written or seen a comment in code similar to "This can't possibly happen!!" ... Usually in response to a failed debugging attempt.
It's really hard to understands all possible execution paths that might result from all possible inputs and program states. "Fail early and fail hard" is a good principle... And indeed one generally in a spirit compatible with DbC.
Beware of bugs in the above code; I have only proved it correct, not tried it.
- Donald Knuth