The @infix Annotation

As a long-time Scala developer, I have to say (even though this will be buried) that this proposal is really ill-conceived. If there’s regret around infix methods, own it and change the language. Whether infix methods are allowed needs to be a property of the language, not whether the library author thought about whether to put an annotation on the method. That is just going to lead to more confusion and ultimately kill infix methods, since it won’t be reliable.

If that’s the goal, then fine – kill infix methods in the language rather than by crippling them. Personally, I think that’s a really arbitrary choice. Clearly, it’s OK for the parser to deal with them, since it already does. Choosing to kill them to enforce someone’s idea of good style is not a good reason to change the language (and to be clear, I see the @infix annotation as tantamount to killing infix methods, since that’s what it will indirectly accomplish after a lot of confusion and damage to the language’s reputation).

Code style should be a function of the team that’s working on it. If I see (or someone on my team sees) questionable infix style in a pull request, we would point it out. Many teams also use linters or what have you. But if something is part of the language, it should be up to me (and my team) if it’s readable and clear.

Either way, if you want to dictate how the language is used, change the language! An annotation at the definition site of a function shouldn’t dictate the semantics of the language.

Personally, I tend towards dot notation in most cases, but I’d like to call out a couple of infix usages that I do use, and the fact that widely used DSLs also use infix notation for readability:

foo match {
  case foo if setOfThings contains foo => ???
  ...
} 

reads pretty nicely to me, and for contains in this situation I always want to use infix notation. If you’re a Scala maintainer and you disagree with me, own it and change the language.

ScalaTest uses infix notation basically everywhere. My tests shouldn’t stop compiling because I have some version of ScalaTest from before they added @infix everywhere.

Please change the language if you hate infix methods. Then we’ll all at least know which way the wind is blowing as far as respecting the users’ choice.

9 Likes