Scala Language Prefer a Functional Style, Reasonably


Example

By default:

  • Use val, not var, wherever possible. This allows you to take seamless advantage of a number of functional utilities, including work distribution.
  • Use recursion and comprehensionss, not loops.
  • Use immutable collections. This is a corrolary to using val whenever possible.
  • Focus on data transformations, CQRS-style logic, and not CRUD.

There are good reasons to choose non-functional style:

  • var can be used for local state (for example, inside an actor).
  • mutable gives better performance in certain situations.