[Python-ideas] Why is design-by-contracts not widely adopted?
mertz at gnosis.cx
Sun Sep 23 03:15:24 EDT 2018
On Sun, Sep 23, 2018, 1:10 AM Marko Ristin-Kaufmann <marko.ristin at gmail.com>
> One explanation that seems plausible to me is that many programmers are
> actually having a hard time with formalization and logic rules (*e.g., *implication,
> quantifiers), maybe due to missing education (*e.g. *many programmers are
> people who came to programming from other less-formal fields). It's hence
> easier for them to write in human text and takes substantial cognitive load
> to formalize these thoughts in code. Does that explains it?
I've tried to explain my own reasons for not being that interested in DbC
in other threads. I've been familiar with DbC libraries in Python for close
to 20 years, and it never struck me as worth the effort of using.
I'm not alone in this. A large majority of folks formally educted in
computer science and related fields have been aware of DbC for decades but
deliberately decided not to use them in their own code. Maybe you and
Bertram Meyer are simple better than that 99% of programmers... Or maybe
the benefit is not so self-evidently and compelling as it feels to you.
To me, as I've said, DbC imposes a very large cost for both writers and
readers of code. While it's possible to split hairs about the edge cases
where assertions and unit tests cannot cover identical ground, the reality
is that the benefits are extremely close between the different techniques.
However, it's vastly easier to take a more incremental and as-needed
approach using assertions and unit tests than it is with DbC.
Moreover, unit tests have the giant advantage of living *elsewhere* than in
the main code itself... This probably doesn't matter so much to writers,
but it's a huge win for readers. Even with doctests—which I'm somewhat
unusual in actually liking—even though the tests live in the same file and
function/class as the operational code, it still feels relatively easy to
separate the concerns visual when reading such code. I just cannot get that
I know you can inside I'm wrong about all this, and my code would be better
and faster if I would accept this niche orthodoxy. But I just do not see
DbC becoming non-niche in any plausible future, neither in Python not in
any other mainstream language. Opinions are free to differ, and I could be
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas