|
|
|
|
|
by tsimionescu
27 days ago
|
|
The first expression is fine, as it uses extremely commonly known precedence rules. The second is more arguable. However, the following expressions should be invalid in any language, and no one should write them even in languages where they are unfortunately allowed: a + b >> c & d && 0 % 9
a >> 4 ? b : c & d ^ 7
|
|
Note that I view ? as a language construct rather than an operator. If for whatever reason someone insisted on including that in the strict left to right requirement the second example still works and is easy to read. I just don't like those semantics as much because the parenthesis in something like a ? ( b >> c ) : d are otherwise unnecessary. The implicit parenthesis of expr ? expr : expr seems preferable to me.