Re:What’s New in Python 3.8
by peterwwillis on Monday October 14, 2019 @07:04PM
(#21253808)
Perl devs have been using the walrus expression for decades, but we just called it "assigning a variable with local scope in an expression".
[ Parent
| on HN ]
The reason why assignment expressions initially were not allowed in Python and why they had to introduce "walrus" was because in languages that used single equal sign for assignment enable to easily make bugs by typing "=" instead of "==".
I find it strange to sacrifice syntactical simplicity for bug prevention in a language that needs deep testing anyway because it's neither nil- nor type-safe. But maybe I'm just to used to inline "=".
A partial solution was already introduced with `with x as y`.
Yup, C and many other languages also have it:
if (ptr = strchr(address, ':'))
port = atoi(ptr + 1);
Re:What’s New in Python 3.8
by iso-8859-1 on Monday October 14, 2019 @11:50PM
(#21255393)
It doesn't do scoping, so not really the same.