Comparison
Pure functionvsReferential transparency
Pure function
you called it twice with the same arguments, got the same answer, and nothing anywhere else changed.
A function whose result depends only on its arguments and which changes nothing outside itself. Purity is what makes a function trivially testable, safely cacheable, freely reorderable and safe to run on several threads — every one of those properties follows from the same two conditions. The design move it suggests is not writing everything this way but knowing which of your functions are, and being deliberate about where the impure ones live.
Full entry →Referential transparency
you replaced the call with the value it returned and the program behaved identically, which is not true of most calls.
The property that an expression can be replaced by its value without changing the program's meaning. It is the formal statement of what purity buys, and it is the licence under which memoisation, common subexpression elimination and lazy evaluation are all safe. It is the thing that quietly stops being true the moment a function reads the clock or a global.
Full entry →