Friday 15 August 2014

Scala Note 4: Imperative Style v.s. Functional Style

Recognition

If code contains any vars, it is probably in an imperative style. If the code contains no vars at all, i.e.,
it contains only vals, it is probably in a functional style. Also prefer methods without side effects.

Scala is not a pure functional language, but a hybrid imperative/functional language.


A balanced attitude for Scala programmers.
Prefer vals, immutable objects, and methods without side effects.
Reach for them first. Use vars, mutable objects, and methods with side effects when you have a specific need and justification for them.


No comments:

Post a Comment