6 ms·
if a = foo() versus: if (a = foo()) Sometimes idiomatic patterns vary based on things which are not amiable to mechanical correction.
by mnarayan01 8y ago
if a = foo()
versus:
if (a = foo())
Sometimes idiomatic patterns vary based on things which are not amiable to mechanical correction.
- munchbunny 8y agoWhile you have a point, I don't think the exception should disprove the rule. Even if a few specific style patterns can't be automated, the bulk can be and it's probably better to have them enforced at the pre-compile stage.
- quxbar 8y agoThe trick is to ban even the correct but (to a human) ambiguous patterns. In this case, I wouldn't let you do assignment on the same line as the conditional.
- squiggleblaz 8y agoWith an `if` it's probably superfluous and therefore bannable without cost, but sometimes it can make a `while` loop so much more concise - since the alternative would be to write the same code before the loop and at the bottom of the loop. It is the cost of inexpressive languages.
- fipple 8y agoIn what language do those produce different results?
- mattnewton 8y agoIn many people’s head-parser, the first one looks like an equality check (but is in fact assignment). The parens try to clue people into “this is an assignment expression!” I think, but personally I wouldn’t allow an assignment expression in an if statement even with parens.