DEV Community

Cover image for Poll: Do You Know What "Idempotent" Means?

Poll: Do You Know What "Idempotent" Means?

Thorsten Hirsch on December 27, 2018

In a very good talk about TLS 1.3 at 35c3 Hanno Böck wondered if web developers know what "idempotent" means. Now before you fall into a rage, Hann...
Collapse
 
stuartpullinger profile image
stuartpullinger

Follow up poll: can you pronounce it? 😊

Collapse
 
qm3ster profile image
Mihail Malo

In 7 languages

Collapse
 
anortef profile image
Adrián Norte

Almost ten years ago it was drilled into my head by the CTO. To this day (and no longer working with him for years) I still fear of him discovering that I didn't make this or that function fully idempotent.

Collapse
 
ben profile image
Ben Halpern

For whatever reason I don't have idempotent in my typical software development vocabulary, even though I know what it means and its conceptual importance. I did implement one of these examples after all.

But I rarely use the word either in speech or in my internal dialog as I'm thinking about things. I certainly use the idea of idempotency, but not the word for some reason.

Collapse
 
rhymes profile image
rhymes

The REST architecture separates resource representation (the response, the state) from the operation. So, repeated GETs will result in the same operation on the server (so it's idempotent), while the actual state might have changed in time.

Instead repeated POSTs will result in new resources being created, so it's not idempotent

It's slightly different from what you intend

Thread Thread
 
jsn1nj4 profile image
Elliot Derhay

By that definition, I guess I have used the concept, even without knowing the word.

Collapse
 
dance2die profile image
Sung M. Kim • Edited

Thank you for introducing the arcane term, that people should be aware of, Thorsten.

I've only heard "of" the term, Idempotent and been using functions/methods without knowing what it was 😅

1️⃣ First example is SQL server not allowing User-defined functions (UDFs) to call stored procedures (sprocs) as sprocs can have side effects (writing/update database) while UDFs do not allow it (as it needs to be pure).

2️⃣ Second example is in React's setState, where it requires to pass a pure function (meaning having no side-effects) to return a new state object instance (for reconciliation optimization).

I've only realized that after reading your linked Wikipedia article under Computer science meaning section in which it reads,

in functional programming, a pure function is idempotent if it is idempotent in the mathematical sense given in the definition.

Collapse
 
loilo profile image
Florian Reuschel

I knew the term from a discussion on GitHub (and had to google it back then), but I had used idempotency for years before — just without knowing that there's a word for it. That's probably the case for a lot of, if not most programmers who don't know idempotency.

(FWIW that's one of the greatest advantages of studying Computer Science in my opinion — programmers without a CS background often use the same concepts, but CS people know their names, which is basically a superpower.)

Collapse
 
sbellware profile image
Scott Bellware

Quick way to tell whether your web app is not idempotent: You use a client-side mechanism to disable (or otherwise obstruct) a submit button once it's been clicked because the same transaction can't be allowed to be submitted more than once. If a transaction can be processed more than once - irrespective of what's happening in the client - the implementation isn't idempotent and is still capable of processing the same thing more than once. It's increasingly rare to see this kind of thing in the wild, but it's still out there.

Collapse
 
senorsmile profile image
Shaun Smiley

NB: I am NOT a webdev... at all.

My definition:
f(f(x)) = f(x)

i.e.
applying the same function f() 1 or more times yields identical output (including side effects).

Idempotent has been a well talked about term in DevOps / Systems Automation circles for a while now. It's also quite popular in functional programming, and of course began in mathematics.

Collapse
 
slitcanvas profile image
Adam Smith

My favourite example of a need for an idempotent function was on an old e-commerce site I worked on. Where rather than having a remove line function it used the add to basket function with negative max int. I would have loved an idempotent function rather than having to deal with the side effects caused by a shortcut. Safe, repeatable, no side effects. That's the idempotent dream :)

Collapse
 
rhymes profile image
rhymes

Another example of idempotency is the REST architecture in which everything but POST should be idempotent. Repeated GETs should yield the same result, same for DELETEs and so on.

Collapse
 
samrocksc profile image
Sam Clark

I'll never forget when I had a senior say "you need to make that an idempotent route".....

Collapse
 
lysofdev profile image
Esteban Hernández

I was aware of the concept but not the word. Great post!

Collapse
 
florimondmanca profile image
Florimond Manca

I already knew what "idempotent" meant from a mathematical point of view, but never really thought about how the concept could be used to build "retry-tolerant" systems, so I went for the unicorn. :-)

Collapse
 
nektro profile image
Meghan (she/her) • Edited
Collapse
 
damian profile image
damian

wait... it's not item potent? my world is shattered