Live data from Hacker News

Idempotence: What is it and why should I care?

cloudingmine.com

1–10 of 77 posts

Re: Idempotence: What is it and why should I care?

#5
One of the practical applications of this concept I've found is that I try to write idempotent database migrations (so rerunning the migration, which is a common necessity while you're developing it, but is also useful if problems occur, won't error).

So in essence both the "up" and the "down" migrations are idempotent and warn if they are not (and why).

Re: Idempotence: What is it and why should I care?

#6

A function f is idempotent if: f(f(x)) = f(x) The "absolute value" function is idempotent: abs(abs(-42)) = abs(-42) The "squared" function is not: sq(sq(7)) != sq(7)

This is about idempotent operations, which are basically state changes that have the same affect if executed multiple times as if executed once:

  $ chmod a+x file
  $ chmod a+x file
This is linked to mathematical idempotence in the sense that an operation is a function which takes some inputs i and the state of the world S and produces a new state S':

S' = f(S, i).

So then if f(f(S, i), i) = f(S, i) then f is idemponent mathematically, and the operation is idempotent in the software sense.

Re: Idempotence: What is it and why should I care?

#9
I once wrote a Jenkins job that created a sub directory every time it ran, if it didn’t exist and somehow managed to write it so every time it ran it went another layer deep, adding another nested subdirectory each time and it was set to reuse the same workspace. After a few months, all the jobs on the server started failing because the worker node ran out of inodes. And that was my introduction to idempotence.

Re: Idempotence: What is it and why should I care?

#10

A function f is idempotent if: f(f(x)) = f(x) The "absolute value" function is idempotent: abs(abs(-42)) = abs(-42) The "squared" function is not: sq(sq(7)) != sq(7)

This is about idempotent operations , which are basically state changes that have the same affect if executed multiple times as if executed once: $ chmod a+x file $ chmod a+x file This is linked to mathematical idempotence in the sense that an operation is a function which takes some inputs i and the state of the world S and produces a new state S': S' = f(S, i). So then if f(f(S, i), i) = f(S, i) then f is idemponen…

You're right, and the technical distinction is warranted, but the definition you give is still not equivalent to that of being mathematically idempotent, since the domain and range of f are not isomorphic.
Post reply on HN