2 ms·
IMO, the "one obvious way to do things" has always been a comforting fiction. There are numerous ways to do everything, the worst offenders forcing people to ma
by DangitBobby 5y ago
IMO, the "one obvious way to do things" has always been a comforting fiction. There are numerous ways to do everything, the worst offenders forcing people to make tradeoffs between debuggability and readability (ie, for loops versus list comprehensions). Many of them are purely about readability (ternary expression versus if blocks) and many of them are about style (ternary expression versus use of or/and short-circuiting). Even so, before the walrus operator, there was never a way to define a variable that only existed in the scope of a particular if statement.
After using pattern matching in Rust and switch statements in JavaScript, I personally am very excited for that addition to Python, but I understand the feature is divisive and will concede it as a matter of opinion.
Edit: turns out the walrus operator does not cause the variable to move out of scope after the if block, which is disappointing. IMO the worse anti-pattern has already been part of the language, which is not creating new scopes for if statements.