Comment by mbid
7 years ago
From wikipedia:
"A unary operation f, that is, a map from some set S into itself, is called idempotent if, for all x in S, f(f(x)) = f(x)."
7 years ago
From wikipedia:
"A unary operation f, that is, a map from some set S into itself, is called idempotent if, for all x in S, f(f(x)) = f(x)."
Instead of checking wikipedia for a general definition of idempotency, check the RFC for the definition that applies to HTTP
9.1.2 Idempotent Methods
Yes, in mathematics, not programming. And a function that doubles a number isn't idempotent even by that definition.
Of course a doubling function is not idempotent!
I think the confusion arises because side-effectful functions can be considered as having type
and so for a garage door toggle you have something like
where the new state is the old one with the door opened/closed as appropriate.
Now the idempotence condition becomes:
but clearly
so this is where the notion comes from. If you abuse notation and just say a function of no arguments can be idempotent then you'll get confusion like this.
But `GET(GET(x))` doesn't make sense, in general (and if it did, then you would not expect it to be idempotent), so clearly idempotency in this context is meant to mean side-effect free. They should probably just say side-effect free, though, to avoid the confusion.
4 replies →
I think because in math you don’t ever have side effects you usually use composition where in programming you usually use a sequence. So to change that function in to how people would implement it means rearranging the internal stuff and then it probably wouldn’t be idempotent be either definition.
But not the reverse. If you are side effect free you must be idempotent.
"Idempotent" is one of those overloaded terms...