[Python-ideas] Why is design-by-contracts not widely adopted?
mertz at gnosis.cx
Mon Oct 1 21:48:18 EDT 2018
On Mon, Oct 1, 2018, 9:13 PM Steven D'Aprano <steve at pearwood.info> 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
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
- Donald Knuth
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas