In Scala I tend to favour writing large chained expressions over many smaller expressions with val
assignments. At my company we\'ve sort of evolved a style for th
I prefer lots of val
s:
def foo = {
val range = (1 to 100).view
val mappedRange = range map { _+3 }
val importantValues = mappedRange filter { _ > 10 } flatMap { table.get }
(importantValues take 3).toList
}
Because I don't know what you want to purpose with your code, I chose random names for the val
s.
There is a big advantage to choose val
s instead of the other mentioned solutions:
It is obvious what your code does. In your example and in the solutions mentioned in most other answers anyone does not know at first sight what it does. There is too much information in one expression. Only in a for-expression, mentioned by @Kevin, it is possible to choose telling names but I don't like them because: