Author Topic: More on precedence rules  (Read 7524 times)

lerno

  • Full Member
  • ***
  • Posts: 247
    • View Profile
More on precedence rules
« on: October 26, 2018, 11:13:00 PM »
In Pony, all operators have mandatory ( ). That is going too far, but maybe we should require them where (1) two or more operators of the same precedence are chained. (2) and where the order of execution is important.

For example, consider a < b > c < d.

Under C/C2 rules that is (((a < b) > c) < d). Here it would be better to explicitly require ( ) be added.

With the new precedence rules == and < has the same precedence. Consequently a < b == c > b becomes ((a < b) == c) > b.

It's a nonsense expression and you should never really do that, but if you were relying on the C behaviour of (a < b) == (c > b) then it can be surprising, even though very few would use the version without parenthesis.

One could require parenthesis in these cases where there often is ambiguity, so the relational operators and possibly logical and/or as well.

It would go with the "don't make it possible to write incorrect code" idea.