|
|
|
|
|
by sgarland
753 days ago
|
|
For a simple example, I think the walrus operator (:=) could be considered clever. I like it, and use it, but the fact that you can declare a variable, store a value in it, and then perform actions depending on its value, all in one line, gives me pause. if (foo := bar()) is not None:
baz(foo)
Whereas the traditionally accepted Python method of dealing with this would be EAFP: try:
foo = bar()
baz(foo)
except AttributeError:
# handle exception
|
|
Where are you expecting an AttributeError to come from? Why are you comfortable catching them from anything inside of the baz(...) invocation?
The traditional method would be to just bind it and check for a null outside the expression.
I don't know why people insisted on pretending binding variables before using them was such a difficulty that it was worth altering the language. Lazy and bad programmers aren't going to stop being lazy and bad when you hand them the ability to name things willy nilly. They'll just use that badly as well.