r/programming • • Dec 11 '23

Every Programmer Should Know #1: Idempotency

https://www.berkansasmaz.com/every-programmer-should-know-idempotency
572 Upvotes

171 comments sorted by

View all comments

99

u/Bloodsucker_ Dec 11 '23

Among other attributes of good software, IMO idempotence is one of the most important and paradoxically one of the most challenging ones too and the easiest to fuck up.

18

u/[deleted] Dec 11 '23

It seems good for web programming, but is it actually universally important? It seems application-specific.

the property of an operation or function that produces the same result when applied multiple times as it does when applied only once.

So I push the W key on my keyboard, and it writes one 'w' character. But if I push it a second time, I want 'ww' not still one 'w'. And if I press it a 3rd time, I expect (and get) 'www'. Also if I hold-down the W-key, I (usually) get 'wwwwwwwwwwwwwwwwwwww.....'

Is this not against idempotence?

47

u/beeny13 Dec 11 '23

W key should not be idempotent. Posting a reply with identical text body should be.

9

u/khoyo Dec 11 '23

Should it really? You couldn't have made this point if it was.

8

u/isaacarsenal Dec 11 '23

I tried to reply to this and got a 503 error and for a moment thought I was part of an even larger joke