osdir.com


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

[Python-Dev] Examples for PEP 572


[Yury Selivanov]
> Wow, I gave up on this example before figuring this out (and I also

> > stared at it for a good couple of minutes).  Now it makes sense.  It's

> > funny that this super convoluted snippet is shown as a good example

> > for PEP 572.  Although almost all PEP 572 examples are questionable.

And another who didn't actually read the PEP Appendix.  See my reply just
before this one:  yes, the Appendix gave that as a good example, but as a
good example of assignment-expression ABUSE.  The opposite of something
desirable.

I've never insisted there's only one side to this, and when staring at code
was equally interested in cases where assignment expressions would hurt as
where they would help.  I ended up giving more examples where they would
help, because after writing up the first two bad examples in the Appendix
figured it was clear enough that "it's a bad idea except in cases where it
_obviously_ helps".

Same way,  e.g., as when list comprehensions were new, I focused much more
on cases where they might help after convincing myself that a great many
nested loops building lists were much better left _as_ nested loops.  So I
looked instead for real-code cases where they would obviously help, and
found plenty.

And I'm really glad Python added listcomps too, despite the possibility of
gross abuse ;-)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20180704/e92ce29e/attachment.html>