[Python-ideas] Pre-conditions and post-conditions

Jacco van Dorp j.van.dorp at deonet.nl
Wed Aug 29 03:23:02 EDT 2018


Op wo 29 aug. 2018 om 03:59 schreef Steven D'Aprano <steve at pearwood.info>:

> On Tue, Aug 28, 2018 at 07:46:02AM +0200, Marko Ristin-Kaufmann wrote:
> > Hi,
> > To clarify the benefits of the contracts, let me give you an example from
> > our code base:
> >
> > @icontract.pre(lambda x: x >= 0)
> > @icontract.pre(lambda y: y >= 0)
> > @icontract.pre(lambda width: width >= 0)
> > @icontract.pre(lambda height: height >= 0)
> > @icontract.pre(lambda x, width, img: x + width <=
> pqry.opencv.width_of(img))
> > @icontract.pre(lambda y, height, img: y + height <=
> pqry.opencv.height_of(img))
> > @icontract.post(lambda self: (self.x, self.y) in self)
> > @icontract.post(lambda self: (self.x + self.width - 1, self.y +
> > self.height - 1) in self)
> > @icontract.post(lambda self: (self.x + self.width, self.y +
> > self.height) not in self)
> > def __init__(self, img: np.ndarray, x: int, y: int, width: int,
> > height: int) -> None:
>
>
> Thanks for your example Marko. I think that is quite close to the
> ugliest piece of Python code I've ever seen, and I don't mean that as a
> criticism of you for writing it or the icontract library's design.
>
>
What, really ? Well, it clearly shows you teach python and don't look much
at code written by people who taught themselves. I taught myself, and the
first .py file I created was over a 1000 lines, and contained the GUI in a
4-deep nested global dictionary, since I'd never seen a style guide at that
point. (I got better)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180829/4b1b0b6d/attachment.html>


More information about the Python-ideas mailing list