|
|
|
|
|
by unwind
435 days ago
|
|
I was not familiar with the term, so I had to look it up. It's about code like this: a := b
the `:=` looks vaguely like a walrus. The most common reference language seems to be Python [1]. The usage is for making assignment remain an expression, so you can do stuff like area = (width := get_width()) * (height := get_height())
or something, and have the top-level expression remain valid since the sub-expressions are assignments that remain expressions, i.e. the assigned value is also the result of the expression.[1]: https://realpython.com/python-walrus-operator/ |
|
Since it was introduced, I have been looking but there has been only a handful of times where I could use it to write clearer code.
I'm curious if anyone actually likes it.
edit: A quick search shows that I do use it regularly in while loops, e.g.: