Kontakt

Immutability and Pure Functions

Data transformations built on immutable data and composed by pure functions in our experience help to reduce complexity and build scalable applications. That's why we recommend to ADOPT these techniques.

What do we mean with scalability?

There are at least the following dimensions to scalability:

  • Applications should scale in regard to the number of users - we want scalable performance
  • Applications should scale in number of developers - ease of development
  • Applications should scale in use-cases - support an increasing number of features

Benefits of Immutability / Pure Functions

  • leads to feature composability: As we effectively prohibit side effects which modify the core domain models, features can be built based on common atoms.
  • can lead to performance in a multi-threaded environment, as the same object can be passed to multiple threads without worrying about locking or race conditions
  • leads to easier-to-reason-about system parts, increasing developer productivity
  • highly performant change detection  by just comparing object references (instead of deep copies) - this is the cornerstone of a high-performant React / Redux application.

Drawbacks

  • performance on modification: Modifying an immutable object by copying and then modifying the copy is of course more expensive than directly changing it in memory.
  • functional programming (FP) (which is often built around these two paradigms) is well-less-known for many developers than object oriented programming.

Implementations