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

Because assignment is an expression. It has nothing specifically to do with the position being a conditional.

Conditionals need an expression, and assignment fits the bill, so it works.



> Because assignment is an expression. It has nothing specifically to do with the position being a conditional.

No, but it has a lot to do with the way humans write code. This is the source of the bug, not the logic. eg Why bother having whitespace that the compiler can't use (typically)? Human readability.

The concession to not take into account human failing, is pathological.


The other partial fix is to stop allowing truthy conditionals. Only allow Boolean values and the only time you it wrong is when you’re assigning to booleans.


Why is assignment an expression and not a statement? Why should an assignment evaluate to a value?




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

Search: