←back to thread

317 points est | 1 comments | | HN request time: 0.201s | source
Show context
korijn ◴[] No.17449188[source]
It feels like we are repeating a mistake the PHP community made years ago. PHP supports assignment in expressions, and the community seems to avoid its use. There are plenty of examples of stackoverflow questions and answers where the problem is caused by coders overlooking an assignment in an expression. You just don't expect assignment to occur in an expression, and its visually similar enough to gloss over it.
replies(4): >>17449245 #>>17449289 #>>17449406 #>>17450205 #
sametmax ◴[] No.17449406[source]
In PHP, the "if ($a = 1)" and "if ($a == 1)" look a lot like each others.

In the Python version, the new "(a := 1)" will stand out compare to the canonical "a == 1" as the ':' and '()' are unexpected here, and scream that it's not regular if test.

replies(3): >>17451677 #>>17451814 #>>17453916 #
dvlsg ◴[] No.17451677[source]
Same problem in Javascript. There's actually a yoda lint rule that encourages you to write your code like (1 === a) instead, so you don't accidentally make that mistake.
replies(1): >>17453341 #
1. makapuf ◴[] No.17453341[source]
I hate Yoda assignment in C. Does no good when assigning to variables. I think it's better to use the weird (on purpose) ((x=13)) and forbid x=13