Hacker News new | past | comments | ask | show | jobs | submit login

I think in certain situations the walrus operator will probably be useful. But it definitely makes code less legible, which makes me cautious. The only useful use case I have found so far is list comprehensions where some function evaluation could be reduced to only one execution with the walrus operator.



> But it definitely makes code less legible, which makes me cautious.

Disagree. In cases where it's useful it can make the code much clearer. Just yesterday I wrote code of the form:

    foos = []
    foo = func(a,b,c,d)
    while foo:
       foos.append(foo)
       foo = func(a,b,c,d)
With the walrus operator, that would just be:

    foos = []
    while foo := func(a,b,c,d):
        foos.append(foo)
Further, I had to pull out 'func' into a function in the first place so I wouldn't have something complicated repeated twice, so it would remove the need for that function as well.




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: