Python Forum

Full Version: Walrus Operator in 3.8
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
https://medium.com/hultner/try-out-walru...30ce0ce601

Seems pretty cool for buffers.
# instead of...
buffer = create_buffer()
while True:
    chunk = buffer.read()
    if not chunk:
        break
    process(chunk)

# ...you'll be able to do this:
buffer = create_buffer()
while chunk := buffer.read():
    process(chunk)
I freaking love the name. Also walruses are fairly ugly so maybe it encourages using it as sparingly as it probably ought to be used :)
I don't know. It seems ugly.
in a matter of 10 minutes of researching this im having mixed emotions. At first i was disgusted, then intrigued. Now I might even like it.

Is this a common operator in some other languages? I cant seem to find much about it other than python.
Isn't this what Guido quit over?
Don't know if I will like it or not, and won't until I find a need for it.
the example above, looks somewhat pretty, not ugly to me.

So far, I don't really have a feeling one way or the other.
I saw definite uses for it when writing t_games, but I don't want t_games to be dependent on the latest version.
(Feb-15-2019, 08:42 PM)metulburr Wrote: [ -> ]Is this a common operator in some other languages? I cant seem to find much about it other than python.
In C/C++ at least, the assignment operator is an expression, rather than a statement like Python, so basically yes C/C++ have this operator but Python is different in the sense that it's two different things instead of one thing. I believe Java assignments are also expressions, though the usefulness is less in Java than C/C++.
(Feb-15-2019, 08:48 PM)Larz60+ Wrote: [ -> ]Isn't this what Guido quit over?
It was the straw that broke his back. He didn't quit over just this, but the way the community reacted pushed him over the edge.

Guido is the one who wanted this to happen. The pushback he got was too much for him to take.

The reason Python didn't have this ability from the start, like C/C++, was to avoid ambiguity in equality checks. That's why there's alternate syntax for it now, so there's still no ambiguity over what's happening.
(Feb-16-2019, 04:29 PM)nilamo Wrote: [ -> ]The pushback he got was too much for him to take.

Programmers can be such uptight purists sometimes. Every CS degree should have a mandatory class named CS 305: You Really Need to Lighten Up.
Quote:Programmers can be such uptight purists sometimes
Don't we all strive for excellence?
It's part of the job.
My wife has another name for it, which I won't mention here.
The fact that everything in a properly functioning program, in the end, has to be either true or false leads us to be pricks!
There's no maybe gate on a chip! (Perhaps on a multi-vibrator?)
Pages: 1 2 3