Redundant parentheses should result in compile errors.


(Amir Michail) #1

This isn’t just a style issue.

Rather, it would force programmers to remember operator precedence better thus resulting in fewer bugs.


(Adrian Kashivskyy) #2

It's hard to understand what you mean, could you provide come code examples?

Regards,
Adrian Kashivskyy
iOS Developer at Netguru

···

Wiadomość napisana przez Amir Michail <a.michail@me.com> w dniu 05.12.2015, o godz. 19:33:

This isn’t just a style issue.

Rather, it would force programmers to remember operator precedence better thus resulting in fewer bugs.
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Nicky Gerritsen) #3

But is this not also often used to make “bigger” expressions / conditions more readable?
I think already the example from https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/AdvancedOperators.html#//apple_ref/doc/uid/TP40014097-CH27-ID41 is a good example
2 + 3 % 4 * 5 is not at all readable for me without parentheses.

-- Nicky

···

On 5 dec. 2015, at 19:33, Amir Michail <a.michail@me.com> wrote:

This isn’t just a style issue.

Rather, it would force programmers to remember operator precedence better thus resulting in fewer bugs.


(Adrian Kashivskyy) #4

2 + 3 % 4 * 5 is not at all readable for me without parentheses.

Agree, it's neither readable, nor predictable, because of the operator precedence. That's why I don't understand why should one omit parentheses in such cases. I'm -1 on this for now.

Pozdrawiam – Regards,
Adrian Kashivskyy

···

Wiadomość napisana przez Nicky Gerritsen <nickygerritsen@me.com> w dniu 05.12.2015, o godz. 19:36:

On 5 dec. 2015, at 19:33, Amir Michail <a.michail@me.com> wrote:

This isn’t just a style issue.

Rather, it would force programmers to remember operator precedence better thus resulting in fewer bugs.

But is this not also often used to make “bigger” expressions / conditions more readable?
I think already the example from https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/AdvancedOperators.html#//apple_ref/doc/uid/TP40014097-CH27-ID41 is a good example
2 + 3 % 4 * 5 is not at all readable for me without parentheses.

-- Nicky
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(John Calsbeek) #5

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

···

On Dec 5, 2015, at 10:42 AM, Amir Michail <a.michail@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.


(Amir Michail) #6

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.

···

On Dec 5, 2015, at 1:40 PM, Adrian Kashivskyy <adrian.kashivskyy@me.com> wrote:

2 + 3 % 4 * 5 is not at all readable for me without parentheses.

Agree, it's neither readable, nor predictable, because of the operator precedence. That's why I don't understand why should one omit parentheses in such cases. I'm -1 on this for now.

Pozdrawiam – Regards,
Adrian Kashivskyy

Wiadomość napisana przez Nicky Gerritsen <nickygerritsen@me.com <mailto:nickygerritsen@me.com>> w dniu 05.12.2015, o godz. 19:36:

On 5 dec. 2015, at 19:33, Amir Michail <a.michail@me.com <mailto:a.michail@me.com>> wrote:

This isn’t just a style issue.

Rather, it would force programmers to remember operator precedence better thus resulting in fewer bugs.

But is this not also often used to make “bigger” expressions / conditions more readable?
I think already the example from https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/AdvancedOperators.html#//apple_ref/doc/uid/TP40014097-CH27-ID41 is a good example
2 + 3 % 4 * 5 is not at all readable for me without parentheses.

-- Nicky
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution


(Adrian Kashivskyy) #7

And that's perfectly understandable and justified because it reduces a huge amount of "pain in the bottom" of looking the precedences up.

Besides, parentheses in calculations are as important as in pure math – I don't understand the reasoning behind the idea of disallowing them.

Pozdrawiam – Regards,
Adrian Kashivskyy

···

Wiadomość napisana przez Amir Michail <a.michail@me.com> w dniu 05.12.2015, o godz. 19:42:

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.

On Dec 5, 2015, at 1:40 PM, Adrian Kashivskyy <adrian.kashivskyy@me.com <mailto:adrian.kashivskyy@me.com>> wrote:

2 + 3 % 4 * 5 is not at all readable for me without parentheses.

Agree, it's neither readable, nor predictable, because of the operator precedence. That's why I don't understand why should one omit parentheses in such cases. I'm -1 on this for now.

Pozdrawiam – Regards,
Adrian Kashivskyy

Wiadomość napisana przez Nicky Gerritsen <nickygerritsen@me.com <mailto:nickygerritsen@me.com>> w dniu 05.12.2015, o godz. 19:36:

On 5 dec. 2015, at 19:33, Amir Michail <a.michail@me.com <mailto:a.michail@me.com>> wrote:

This isn’t just a style issue.

Rather, it would force programmers to remember operator precedence better thus resulting in fewer bugs.

But is this not also often used to make “bigger” expressions / conditions more readable?
I think already the example from https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/AdvancedOperators.html#//apple_ref/doc/uid/TP40014097-CH27-ID41 is a good example
2 + 3 % 4 * 5 is not at all readable for me without parentheses.

-- Nicky
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution