architect-handbook

Software Architect Handbook

View on GitHub

Referential Transparency

An expression is called Referentially Transparent if it can be replaced with its corresponding value without changing the program’s behavior. Otherwise, it’s called Referentially Opaque.

This requires that the expression is pure, that is to say the expression value must be the same for the same inputs and its evaluation must have no side effects.

Importance

The importance of referential transparency is that it allows the programmer and the compiler to reason about program behavior as a rewrite system.

This can help in proving correctness, simplifying an algorithm, assisting in modifying code without breaking it, or optimizing coed by means of memoization, common subexpression elimination, lazy evaluation, or parallelization.