top | item 46000024

(no title)

knome | 3 months ago

a pure function doesn't have side effects. it doesn't read from nonlocal state or trigger distant changes nor perform any manner of io.

a pure function doesn't change its inputs, it simply uses them to craft it's outputs.

bringing in an object or function via parameter to perform these side effects still leaves the function impure.

discuss

order

1718627440|3 months ago

I agree that a return type and a parameter are quite different things in a specific implementation, but on an abstract level, they are basically the same and there is now reason to distinguish between output parameters and the return value other than due to language syntax.

I don't see how mergeing an input and an output parameter to a single in/out parameter makes any difference, other than making it inconvenient for the caller to keep the old state around, which is often what you want. The fact that the callee than can derive the new state from the old state by only specifying the changed values does not fundamentally change anything and is only convenient for the implementation.