Re:“I'm basically giving myself a permanent vacation from be...
by nas on Thursday July 12, 2018 @02:45PM
(#17517466)
That's pretty much the main use of the new syntax. When you have a cascade of regexes, it is even better:
if m := re.match(...):
...
elif m := re.match(...):
...
The world is not coming to an end, as some detractors of the PEP might think. The new syntax is a win in a number of cases. Otherwise, you don't need to use it. The concern for abuse is way overblown. I could live without it (voted -1 on the idea originally) but now that it is in, think it is fine.
Re:“I'm basically giving myself a permanent vacation from be...
by marcosdumay on Thursday July 12, 2018 @04:34PM
(#17518376)
Many languages solve that with pattern matching, like in Haskell:
case f <...> of
Nothing -> -- Handles the problem values
Just m -> -- do stuff with m
This is, honestly, much better than an assignment expression. Side-effect expressions always bring problematic cases.
Re:“I'm basically giving myself a permanent vacation from be...
by makecheck on Thursday July 12, 2018 @01:47PM
(#17516951)
Yep, and common for regular expressions. I’d alwayed liked the simplicity of Perl’s “if ($x =~ /.../) {“ and in Python you had to create the match object before you could test it. Assignment expressions should work nicely there.
I'm sick and tired of writing stuff like
m = f( <...> )
if m:
Trivial as it may be, I for one welcome this.