design by contract versus doctest
Colin Blackburn
colin.blackburn at durham.ac.uk
Tue Apr 6 08:27:36 EDT 2004
On Tue, 06 Apr 2004 12:41:45 +0100, Peter Hickman <peter at semantico.com>
wrote:
> Looking at the Eiffel site the contract is enforced within the called
> function.
Only while checking is turned on. It is a design philosophy. You specify
the pre and post-conditions before code is even thought of, it is part of
the design.
> 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
This says that *if* the pre-conditions are met (by the caller) *then* the
post-conditions will be guaranteed to be met (by the called method.) All
callers know this because the contract is publicly specified. New callers
can make use of this method because they know what is required of them and
that a given result will be assured if those requirements are met. They
know this because the method has been designed correctly for these
constraints. If the pre-conditions aren't met then not sensible result is
guaranteed.
Colin
--
More information about the Python-list
mailing list