News for hackers. Stuff that matters.
Re:Dennis Ritchie on the priorities of && || vs. == etc. (1982) by djur on Friday January 05, 2024 @11:22PM (#38888393)
Most people might agree with that, I don't know, but I know I don't think your first example is clearer. And I've had the operator precedence rules memorized for decades. Parentheses save my brain a step.

The second example is irrelevant because addition is commutative so the parentheses are meaningless. (This is why languages shouldn't override + to be a concatenation operator.)

Re:Dennis Ritchie on the priorities of && || vs. == etc. (1982) by tsimionescu on Saturday January 06, 2024 @02:48AM (#38889403)
The important part that makes the parens in the second operation unnecessary is that addition is associative, not that it's commutative. And concatentation is also associative, so even if those were strings, the parens would still be unnecessary.

That is, (a+b)+c == a+(b+c).

Interestingly, C integer addition is not actually associative, since (1+INT_MAX) + (-1) is UB, but 1+(INT_MAX+(-1)) should in principle be defined as INT_MAX.

Re:Dennis Ritchie on the priorities of && || vs. == etc. (1982) by xigoi on Saturday January 06, 2024 @03:43PM (#38895251)
And floating-point addition is not associative in any language: