←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 #
1. johannes1234321 ◴[] No.17449289[source]
Before there were iterators in PHP `while ($row = fetch_row())` was the only sensible iteration pattern.

Before there were exceptions `if ($result = query())` was the cleanest error-checking approach.

Also PHP didn't invent that syntax in any way, but followed C (in the end early PHP was a simplified C created by a C programmer) it only later git higher level constructs making this less needed.