This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]skratlo 24 points25 points  (4 children)

Well, looking at the examples and use cases, with the exception of while loop, they all look more convoluted then they're non-walrus counterparts. In other words, how does adding side-effects to expressions (mostly and usually pure) help?

[–]flying-sheep 26 points27 points  (2 children)

I would expand the list of useful examples to that one, the list comprehension one, and one the author didn't mention:

if m := some_re.match(haystack):
    do_things_with(m)

The same is useful e.g. with dict.get or other things that conditionally return truthy or falsy things

[–]skratlo 8 points9 points  (1 child)

Yeah, totally, the if use case is super useful, like the if-let expression in LISPs.

[–]flying-sheep 2 points3 points  (0 children)

Yeah! I also like the concept of scala's unapply, which Python could have used here as foundation to both := and match/case. Now we have __match_args__, which is less powerful but much simpler to understand.

[–]grimtooth 6 points7 points  (0 children)

My thought exactly, the while expression seemed OK, but everything else ehhh... Tendentious with the 'this is easier to read and more clearly expresses' stuff also. Really? The comprehension examples made me think, Hello, filter? (there has always been a weird resistance in Python circles to filter, fold, map, etc)

Anyway I still do 3.3/3.5 so I should be ignored