4 ms·
> side-effect-free? No, those are pure. A pure, idempotent function would be one where f(f(x)) = f(x). An idempotent function could have side-effects. Imagin
by jolmg 6y ago
> side-effect-free?
No, those are pure.
A pure, idempotent function would be one where f(f(x)) = f(x).
An idempotent function could have side-effects. Imagine turn_on() where if it's already on, then nothing happens and it just stays on.
- tyingq 6y agoI think there's two different readings of "side effect free" here. The fact that nothing happens on the second+ invocation is, for me, the example of no unwanted side effects. An unwanted side effect might be sending more voltage down the line on each invocation...120, 240, 360.
- jolmg 6y agoSide-effect is a very well-established term, though[1]: > In computer science, an operation, function or expression is said to have a side effect if it modifies some state variable value(s) outside its local environment, that is to say has an observable effect besides returning a value (the main effect) to the invoker of the operation. > The fact that nothing happens on the second+ invocation is, for me, the example of no unwanted side effects. I don't think you'll ever find a definition that says something about second invocations. [1] https://en.wikipedia.org/wiki/Side_effect_(computer_science) https://en.wikipedia.org/wiki/Side_effect_(computer_science)
- chrisweekly 6y agoQuite right. How about "same-result-returning"?
- jolmg 6y ago"same-result-returning" sounds like pure functions which return the same result when given the same arguments. I prefer entropicdrifter's "one-and-done".