3 ms·
Should `x == 1 or y == 3` be a syntax error? Because that’s operator precedence too.
by zarzavat 3y ago
Should `x == 1 or y == 3` be a syntax error? Because that’s operator precedence too.
- kragen 3y agothat'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
- zarzavat 3y agoThere 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.
- kragen 3y agoit isn't crystal clear to everyone, smart guy, it's only clear if you're familiar with it
- ctrw 3y agoThat is type inference actually.
- boxed 3y agoyea it should