3 ms·
Referential transparency is a handy thing to think about in OOP as well as functional programming. If you provide the same parameters to a function, will you a
by lemmsjid 7y ago
Referential transparency is a handy thing to think about in OOP as well as functional programming. If you provide the same parameters to a function, will you always get the same result? If yes, and if the function is 'pure', e.g. does not result in some side effect like state manipulation, you could replace the function itself with the output of that function. If so, and the function is computationally expensive, you can memoize the function, which is a specific form of caching where you auto cache the results by the parameters passed to the function.
This is a handy chain of reasoning in any language, and in a more dedicated functional language might be supported as a concept in the language itself.
Like in OOP, you don't have to have that term memorized to actually use a functional language, just remember the pattern.