Referential transparency is a fancy term that is attached to a computable expression. A piece of code is referentially transparent if we can safely replace that piece of code with the value it computes and vice-versa, anywhere where that piece is used, without changing the meaning or result of our program.

If you have a pure function that is deterministic, its entire call can be replaced with the output. This is referential transparency. If you store outputs in a cache and map inputs to cache locations, sometimes you avoid calling entirely by just hitting the cache.

Referential transparency describes the purity aspect of functional programming: only expressions that compute values and don’t produce side effects of interacting with the world in any way.

https://blog.rockthejvm.com/referential-transparency/


🌱 Back to Garden