design by contract versus doctest

Colin Blackburn colin.blackburn at durham.ac.uk
Tue Apr 6 07:03:42 EDT 2004


On Tue, 06 Apr 2004 06:51:16 -0400, Peter Hansen <peter at engcorp.com> wrote:

> Yermat wrote:
>
>> Peter Hansen wrote:
>>> But I'm certainly no expert in (or proponent of) DBC...
>>  see http://www.python.org/doc/essays/metaclasses/Eiffel.py
>> to now how to do (at least one way to) design by contract in Python.
>
> This doesn't appear to do what the OP says it should do.
> I see preconditions which, while coded in separate methods
> from the code for which it is written, still executes
> every time the method is called.  That is, in terms of the
> sequence of code, it's the same as just putting the check
> in at the top of the called method.

In this case yes because python does not support DbC within itself.  
However, in a language that does support DbC (Eiffel) these checks can be  
turned on during the implementation phase and turned off in the delivered  
code. There are techniques in python, java and other languages to  
implement DbC using comments and documentation, ie the contract checks are  
only executed when a tool/module able to process the structure comments is  
loaded.

DbC though is about design rather than just a way testing of parameters.  
It is a philosophy of program design. See Object Oriented Software  
Construction, ed 2, by Bertrand Mayer.

Colin
--



More information about the Python-list mailing list