Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This is just one of the many reasons why I like Python.

    > if a = 3:
           ^
    SyntaxError: invalid syntax


Rust has an interesting take on that, it's not a syntax error to write "if a = 1 { ... }" but it'll fail to compile because the expression "a = true" returns nothing while "if" expects a boolean so it generates a type check error.

Of course a consequence of that is that you can't chained affectations (a = b = c) but it's probably a good compromise.


Well in Rust ypu couldn't have = return the new value in general anyway, because it's been moved. So even if chained assignment did work, it'd only work for copy types, and really, a feature that only saves half a dozen characters, on a fraction of the assignments you do, that can only be used a fraction of the time, doesn't seem worth it at all.




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

Search: