design by contract versus doctest

Peter Hickman peter at semantico.com
Tue Apr 6 07:41:45 EDT 2004


aku wrote:
> But in "design by contract" this responsibility is squarely 
> on the shoulders  of the caller, and is *not* checked in
> the function.

Are you sure about this. If the called function did the checking then it 
will always be checked and the checks would be in one place and easy to 
update. If it the checks were done by the caller then the tests need to 
be placed everywhere the function is called. That alone would be a 
maintenance mightmare.

Looking at the Eiffel site the contract is enforced within the called 
function.

put (x: ELEMENT; key: STRING) is
     -- Insert x so that it will be retrievable through key.
     require
         count <= capacity
         not key.empty
     do
         ... Some insertion algorithm ...
     ensure
         has (x)
         item (key) = x
         count = old count + 1
     end

But then this is the python news group so I expect the father of DbC, 
Bertrand Meyer, is wrong.

No Smilley



More information about the Python-list mailing list