[Python-ideas] Simplicity of C (was why is design-by-contracts not widely)

Stephen J. Turnbull turnbull.stephen.fw at u.tsukuba.ac.jp
Mon Oct 1 13:50:34 EDT 2018

Marko Ristin-Kaufmann writes:

 > Do you mean annotating an abstract class with contracts or
 > annotating the actual functions in abc module?

I mean the functions in the abc module.

 > Inheriting of contracts also proved useful when you define an
 > interface as a group of functions together with the contracts. You
 > define the functions as an ABC with purely static methods (no
 > state) and specify the contracts in that abstract class.

I can envision how that would work in a situation with application-
specific classes, even in a deep hierarchy, with some discipline.
However, Python does not necessarily conform to that kind of
discipline.  I suspect that Pythonic programming styles are not
terribly amenable to inheritance of contracts.  I think the ABC module
is most likely to provide a strong evidence that I'm wrong: if
contract inheritance, and in general the contracting style of
programming, works well for that module, it will work for anything
written in Python.

By the way, I'm not asking you to do this; you've already provided
both the icontract module and a rather complete annotation of a
sizeable stdlib module.  Your work is appreciated!  Of course I'd be
happy to see a similar treatment of abc, but it's also a reasonable
candidate for thought experiments, or a sample of a few cases.


More information about the Python-ideas mailing list