3 ms·
My vision of a language like Python would be only 1-way to do things, and in the event someone wants to add a 2nd way, a vote is taken. By that standard, the w
by orangecat 7y ago
My vision of a language like Python would be only 1-way to do things, and in the event someone wants to add a 2nd way, a vote is taken.
By that standard, the walrus operator is not only acceptable but essential. Right now there are at least 3 ways to process data from a non-iterator:
# 1: loop condition obscures what you're actually testing
while True:
data = read_data()
if not data:
break
process(data)
# 2: 7 lines and a stray variable
done = False
while not done:
data = read_data()
if data:
process(data)
else:
done = True
# 3: duplicated read_data call
data = read_data()
while data:
process(data)
data = read_data()
There's too many options here, and it's annoying for readers to have to parse the code and determine its actual purpose. Clearly we need to replace all of those with:
while (data := read_data()):
process(data)
Yes, I'm being a bit snarky, but the point is that there is never just one way to do something. That's why the Zen of Python specifically says one "obvious" way, and the walrus operator creates an obvious way in several scenarios where none exist today.
- BuckRogers 7y agoI have no opinion on this new feature, so I can't really engage in that debate over it. I still see no reason for smaller languages like Python to not operate as a true direct democracy. There's clearly frustration over the leadership in the PSF, so much so that Guido capitulated under the stress.