[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Python-Dev] Examples for PEP 572

[Serhiy Storchaka]

> > Sorry, this PEP was rewritten so many times that I missed your
> [Tim's] Appendix.

> >

> >> while total != (total := total + term):

> >>     term *= mx2 / (i*(i+1))

> >>     i += 2

> >> return total

> >

> > This code looks clever that the original while loop with a break in a

> > middle. I like clever code. But it needs more mental efforts for

> > understanding it.

> >

> > I admit that this is a good example.

> >

> > There is a tiny problem with it (and with rewriting a while loop as a

> > for loop, as I like). Often the body contains not a single break. In

> > this case the large part of cleverness is disappeared. :-(

[Ivan Pozdeev]
> It took me a few minutes to figure out that this construct actually

> > checks term == 0.

> >

> > So, this example abuses the construct to do something it's not designed

> > to do: perform an unrelated operation before checking the condition.

> > (Cue attempts to squeeze ever mode code here.) I would fail it in review.

> >

> > This "clever" code is exactly what Perl burned itself on and what

> > Python, being its antithesis, was specifically designed to avoid.

So you didn't read the PEP Appendix at all, and Serhiy did but apparently
skipped reading what the PEP _said_ about that example.  It was clearly
identified as abuse:  a case in which using assignment expressions made the
code significantly WORSE.  I gave examples of both "wins" and "losses"
while staring at real code - I wasn't searching for "proof" that a
pre-determined conclusion was justified.

So I wholly agree with you (Ivan) about that example - and that it struck
Serhiy as a good example convinces me more than before that there's no
overlap in the ways Serhiy and I view this part of the world ;-)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20180704/84b9ca8c/attachment.html>