ASCII operators (such as
->
) should be preferred over their fancy unicode equivalents (such as→
).
While they’re supposed to be equivalent, they’re not, at least as far as priority is concerned:
->
has a lower priority than /
→
has a higher priority than /
This makes the following code legal:
1 -> 4 / 2 // Equivalent to 1 -> (4 / 2)
// res0: (Int, Int) = (1, 2)
The following code, on the other hand, isn’t:
1 → 4 / 2 // Equivalent to (1 → 4) / 2
// error: value / is not a member of (Int, Int)
// 1 → 4 / 2 // Equivalent to (1 → 4) / 2
// ^^^^^^^
This violates reasonable assumptions about the behaviour of unicode operators, and is an accident waiting to happen. Better to avoid them altogether and rely on fonts with ligature support or editor support for fancy display.
As it happens, the feature is controversial enough that it’s going to be deprecated in an upcoming Scala version.
Linter | Rule |
---|---|
Scalastyle |