You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allow chaining of comparison operators: a < b <= c and a > b >= c
should compile to a < b && b <= c and a > b && b >= c
Example:
if (0 < variable < 100) { // Do something }
This should simplify some rather common cases where a variable should be tested if it is between values.
Rules:
Can be chained any number of comparison operators. The examples are with 3 vars and 2 operators, but with 4 or 5 operators should be legal. Example: a <= b < c == d < e
Sure it gets less and less readable as the values pile up, but it is still shorter and more readable than a <= b && b < c && c == d && d < e and less error prone (the user won't use || instead of && by mistake, since there is no && or || anywhere).
The chain should be replaced with the corresponding operators and && at compile time.
Allowed operators are <, <=, >, >=, and ==.
!= should not be allowed, since it could lead to occasional confusion. For example: a != b != c
Are you testing for b to be different to a and c (but a and c could be the same) or are you testing all 3 to be different? The compiler will compile to the former but it is unclear whether the user didn't mean the latter (and probably did mean the later!).
The operators should be compared in only one direction. For example: a > b < c and a < b > c should be illegal and throw a compile error.
So if there is even a single < or <= then the user can't use > or >= in the chain. The reason is that it becomes hard to read and reason, especially if many more are chained.
The text was updated successfully, but these errors were encountered:
Allow chaining of comparison operators:
a < b <= c
anda > b >= c
should compile to
a < b && b <= c
anda > b && b >= c
Example:
if (0 < variable < 100) { // Do something }
This should simplify some rather common cases where a variable should be tested if it is between values.
Rules:
a <= b < c == d < e
Sure it gets less and less readable as the values pile up, but it is still shorter and more readable than
a <= b && b < c && c == d && d < e
and less error prone (the user won't use || instead of && by mistake, since there is no && or || anywhere).a != b != c
Are you testing for b to be different to a and c (but a and c could be the same) or are you testing all 3 to be different? The compiler will compile to the former but it is unclear whether the user didn't mean the latter (and probably did mean the later!).
a > b < c
anda < b > c
should be illegal and throw a compile error.So if there is even a single < or <= then the user can't use > or >= in the chain. The reason is that it becomes hard to read and reason, especially if many more are chained.
The text was updated successfully, but these errors were encountered: