design by contract versus doctest
Yermat
loic at fejoz.net
Tue Apr 6 07:50:02 EDT 2004
Colin Blackburn wrote:
> 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
> --
Hi,
Not really each time !
As it uses "assert", it is turn off by using -O option of python or by
removing the metaclass ! So it work exactly as DBC implemented in
Eiffel. His author is Bertrand Meyer (with an 'e').
So please re-read it again !
Yermat
More information about the Python-list
mailing list