3 ms·
WRT pragmatism, why val transformedCollection = collection map transformer instead of val transformedCollection = collection.map(transformer) ?
by JackFr 11y ago
WRT pragmatism, why
val transformedCollection = collection map transformer
instead of
val transformedCollection = collection.map(transformer)
?
- 0xfaded 11y agoThe 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
- J_Darnley 11y agoIf learning Lua has taught me one thing it is that I hate function calls without parentheses.
- bjz_ 11y agoSame with Ruby. So hard to understand what is going on - and unlike Scala there is not even any and typechecking to help.