Re:“I'm basically giving myself a permanent vacation from be...
by sevensor on Thursday July 12, 2018 @04:08PM
(#17518184)
My reaction was the opposite -- I didn't know about PEP572, read it immediately after this retirement announcement. My response was, "where has this feature been all these years?" I'm delighted by the addition -- it removes a lot of "loop and a half" ugliness without adding do loops, it simplifies list comprehensions, it lets you remove opportunities to make mistakes, and it doesn't let you put a single-equals assignment inside a conditional as a typo.
Re:“I'm basically giving myself a permanent vacation from be...
by sneakermoney on Thursday July 12, 2018 @06:11PM
(#17519038)
Same here, I often find myself writing a loop-and-a-half and will on occasion repeat expressions to get around extra lines (if I cared about performance, I wouldn't be writing it in Python).
I feel like a lot of the resistance is from people who think this is somehow bad style, because it's associated with a source of bugs in other languages. The same kind of people will argue endlessly against having 'goto' in a language, even when it can clearly make for cleaner code (eat it, Dijkstra!) in some cases.
Re:“I'm basically giving myself a permanent vacation from be...
by sevensor on Friday July 13, 2018 @09:17AM
(#17522652)
I think EWD was basically in the right to push hard for structured programming, but I also like Knuth's nuanced take:
Re:“I'm basically giving myself a permanent vacation from be...
by bogomipz on Friday July 13, 2018 @12:08AM
(#17520460)
Can you explain what a "loop-and-a-half" is in Python?
Re:“I'm basically giving myself a permanent vacation from be...
by blake_himself on Friday July 13, 2018 @12:37AM
(#17520537)
x = stuff
while x:
x = stuff
Re:“I'm basically giving myself a permanent vacation from be...
by Delgan on Friday July 13, 2018 @03:36AM
(#17521139)
On the contrary, loop-and-a-half is intended to avoid repeating stuff outside and inside of the loop body.
while true:
x = stuff
if not x:
break
Re:“I'm basically giving myself a permanent vacation from be...
by chucksmash on Sunday July 15, 2018 @12:57AM
(#17533866)
GPs example is perfectly valid as well - this is just a restatement of the same logic in a way that keeps the logic contained within the loop at the cost of using a conditional plus a break inside of an unconditional loop. See [0]:
Another motivating code pattern is the "loop and a half".
It was once common for processing a file by line, but that
has been solved by making file objects iterable; however
other non-iterable interfaces still suffer from patterns
like:
line = f.readline()
while line:
... # process line
line = f.readline()
or like this:
while True:
line = f.readline()
if not line:
break
... # process line
Either of those could be replaced with a much more clear
and concise version using an assignment expression:
while line := f.readline():
... # process line
[0]: https://lwn.net/Articles/757713/
Re:“I'm basically giving myself a permanent vacation from be...
by Tehnix on Thursday July 12, 2018 @01:37PM
(#17516852)
> Well, when he is dealing with arguments as silly as "but we will confuse = with ==)...
You clearly never had exposure to a PHP codebase. If people can trip up, people will trip up.
Re:“I'm basically giving myself a permanent vacation from be...
by joshuamorton on Thursday July 12, 2018 @02:16PM
(#17517193)
Guido (along with most core devs) are actively against c-style assignment. This pep was a compromise that Guido felt was good.
But c-style assignment in Python was never going to happen, not should it have.
Thanks Guido for fantastic language. I wouldn't find love for programming if it wasn't for you.