5 ms·
idempotent -> side-effect-free? safely-repeatable?
by chrisweekly 6y ago
idempotent -> side-effect-free? safely-repeatable?
- tyingq 6y agoAh, that's helpful. "Safely repeatable, with no side effects" will be my new answer if anyone asks.
- chrisweekly 6y agoWell, per others' responses the "no side effects" part is not quite accurate. The definition in plain English is actually pretty simple: idempotency = "has the same effect, no matter how many times it's run". Like a dedicated "Power On" button (vs a "power toggle" button).
- marcosdumay 6y ago> side-effect-free Hum... No, that's not the meaning at all. > safely-repeatable And now you'll get stuck explaining exactly what "safe" means.
- 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".