[swift-evolution] Redundant parentheses should result in compile errors.

John Calsbeek john.calsbeek+lists at gmail.com
Sat Dec 5 12:52:22 CST 2015


> On Dec 5, 2015, at 10:42 AM, Amir Michail <a.michail at me.com> wrote:
> 
> Generally speaking, people put parentheses in expressions not to improve readability but because they can’t remember certain operator precedences and don’t want to bother looking them up.

Even if this is true, there exist cases where parentheses express intent, including cases where precedence is not in question.

For example, when working with floats I can rewrite `a * b * c * d` as `(a * b) * (c * d)`, whether for numerical reasons or performance reasons, but if I can only insert relevant parentheses, I must instead write `a * b * (c * d)`. That seems less clear—`c` and `d` are no more specially related than `a` and `b` are.

Or are you proposing forbidding parentheses whenever they don’t change precedence but allowing parentheses when they don’t change associativity?

On a different note: how would you ever _explain_ precedence without writing malformed code? Or write tests that verify operator precedence in a clear manner?

Cheers,
John


More information about the swift-evolution mailing list