News for hackers. Stuff that matters.
Re:We need to talk about parentheses by zarzavat on Monday February 12, 2024 @07:06AM (#39343921)
Should `x == 1 or y == 3` be a syntax error? Because that’s operator precedence too.
Re:We need to talk about parentheses by kragen on Monday February 12, 2024 @07:22AM (#39344034)
that's certainly a plausible position; in lisp (or = x 1 = y 3) is generally an error; even if it's not an error it doesn't mean what you intend it to. having to write (x == 1) || (y == 3), similar analogous to the code you'd write in lisp, would be only a minor burden

in c, x == 1 || y == 3 works fine, but unfortunately the bitwise operators have the wrong precedence; x & 2 == 2 is parsed as x & (2 == 2), which is never what you meant. so even the best software designers have made terrible blunders in precedence design

math formulas are a bigger issue; 3*x**2 + x/2 + 1 is a lot better than the fully parenthesized version

Re:We need to talk about parentheses by zarzavat on Monday February 12, 2024 @11:38AM (#39346919)
There are of course operations with unclear precedence relationships and it’s completely reasonable to want to force parentheses when composing those operations.

However, there are also operations with crystal clear precedence relationships, such as logical conjunction and comparison, and in that case it has to be asked what exactly would the parentheses be there for?

In lisp the answer is: to enable syntactic homogeneity and to enable macros.

But in other languages like Python that don’t have sexpr based syntax, parenthesizing everything would just be pointlessly unreadable.

Re:We need to talk about parentheses by kragen on Tuesday February 13, 2024 @03:25AM (#39355695)
it isn't crystal clear to everyone, smart guy, it's only clear if you're familiar with it
Re:We need to talk about parentheses by ctrw on Monday February 12, 2024 @07:37AM (#39344126)
That is type inference actually.
Re:We need to talk about parentheses by boxed on Tuesday February 13, 2024 @03:07AM (#39355602)
yea it should