Functions that have no effect on global state

50 Views Asked by At

We have the notion of a pure function, whose return value depends only and entirely on its parameters, and which does not change global state.

Example:

def f(a, b):
    return a+b

What would be the correct term for a function that only meets the latter criterion? For example, a function (in a garbage collected language) that allocates a new mutable structure on each call, such that the return value is different for identical parameters?

Example:

def f(a, b):
    return [a, b]

The importance of this classification, from my perspective, is that it is significant to an optimizer: if a function is of this kind, then calls to it can be deleted whenever the return value is not being used. The most concise description I know of is 'calls to this function have no side effects', but it seems like there should be a more concise term.

0

There are 0 best solutions below