3 ms·
The scala style guide suggests that the dotless notation be used for pure (side-effect-less) operations.
by 0xfaded 11y ago
The scala style guide suggests that the dotless notation be used for pure (side-effect-less) operations.
- hibikir 11y agoIf there is a language where the style guide is rarely followed, it's Scala. The dotless notation gets complicated easily the moment you try to extend it past one function call, as you start counting to figure out the order of operations. In fact, even using the shortcut of just using a function name instead of {x=> f(x)} or f(_) is seen as bad form in plenty of places, as knowing if a function has zero parameters, one m ten, or if it's varargs is very important information. I'd limit dotless to very few cases, like symbolic operators, and very organic DSLs, and even then, it doesn't really work all the time: Just look at ScalaTest: Even Bill's wizardry doesn't let us say that "x should be 2": We have to write "x should be(2)", or "x shouldBe 2". If it wasn't for symbolic operators, which are useful in some cases, I'd go as far as to not miss the existence of the feature at all.
- 0xfaded 11y agoAgreed the style guide is a guideline at best. I've moved to the dotless notation because I like that it provides a way to indicate pure code. Postfix operators are poorly supported though. (xs map { x => x.key -> x }).toMap