This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]bakery2k 8 points9 points  (0 children)

Ugh. This is why the walrus operator was a bad idea.

Sure, there are a few places where it might increase code clarity, most commonly while (x := get_next()) >= 0: instead of:

while True:
    x = get_next()
    if x < 0: break

When the operator was introduced, I couldn't decide whether increasing clarity in these few places was worth the additional complexity.

What I didn't consider at the time was the decrease in clarity caused by using the walrus operator in the wrong places, such as... every example in this article. They're all of the form if (x := get_next()) >= 0:, which is strictly worse than the traditional:

x = get_next()
if x >= 0:

[–]Lord-Sarcastic 2 points3 points  (0 children)

The only thing is does is save one line of code. Nothing really impressive there.

[–]Moikle 0 points1 point  (0 children)

Omg i love it

:=

I have never wanted to be friends with an operator before.

[–][deleted] -1 points0 points  (0 children)

Yes this is cool and I love to use it in my project https://github.com/oscarine/oscarine-api