design by contract versus doctest

aku aku at europe.com
Mon Apr 5 11:02:02 EDT 2004


There seems to be a contradictive approach in 
these two things. Example: In the doctest documentation
(http://www.python.org/doc/current/lib/module-doctest.html)
a required precondition (i.e. n is an integer and >= 0)
is verified in the function itself:

if not n >= 0:
        raise ValueError("n must be >= 0")

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

I'm confused as to what the "best" approach is.

Isn't it so, that by applying DBC, a lot of unittests can be
made redundant?

shan.





More information about the Python-list mailing list