5 ms·
The mathematical term for a function that is the same when applied multiple times giving you the same results is called "idempotent" which translates to "same p
by notthemessiah 9y ago
The mathematical term for a function that is the same when applied multiple times giving you the same results is called "idempotent" which translates to "same power". f^n(x)=f(x) for some positive natural number n and any x.
https://en.wikipedia.org/wiki/Idempotence https://en.wikipedia.org/wiki/Idempotence
- hellofunk 9y agoI had a senior dev interview with a major company in SV last year where the lead and hiring manager claimed that the description for this behavior was "side-effect free". I didn't want to ruin my chances by correcting him that side-effects and idempotence refer to different qualities. I passed the interview, but I've never forgotten that. The guy also seemed to have washed into the interview off his surf board. Oh well. It was a very major company, so I let it all go.
- Jach 9y agoYou may have just been victim to the "let's see if they take a risk and correct me on my BS" test some interviewers give. Or they just didn't get it, that happens too. Some won't admit they're wrong even in the face of a mathematical proof..
- dylanpyle 9y agoIn the context of software it seems like the word has pretty broadly adopted the meaning of "side-effect free". It's even made it to Wikipedia: https://en.wikipedia.org/wiki/Idempotence#Computer_science_meaning https://en.wikipedia.org/wiki/Idempotence#Computer_science_m... One notable example: Stripe's "idempotency keys": https://stripe.com/blog/idempotency https://stripe.com/blog/idempotency
- twic 9y agoI understand 'idempotent' not as 'having no side effects' but as 'having the same side effects whether performed one or many times'. This is side-effect free: echo hello This is side-effectful, but idempotent: echo hello >world This is side-effectful and not idempotent: echo hello >>world
- Gaelan 9y agoInterestingly, in this case the non-idempotent option is less safe.
- dragonwriter 9y agoNon-idempotent options are always unsafe; safe operations are a subset of idempotent operations. (I suspect you meant “safe” in a different sense, but I couldn't resist.)
- twic 9y ago> safe operations are a subset of idempotent operations Definitely not. 'Safe' means too many things in different contexts to make sweeping statements like that. Here's one i came across recently. You are interacting with a stock exchange. You have sent an order to buy 100 shares of Twitter stock at some price, and it is now resting on the order book, waiting for orders to sell at that price. You see that the character limit on tweets is being increased, and decide that you don't want to buy 100 shares, but only 90, so you send a message to modify your order. At the same time, two other people, who have also seen the news, decide to dump their holdings of 90 shares each by sending sell orders at the price you are bidding. Their messages arrive just before and after yours. What happens? If the message to reduce your order is a nasty non-idempotent one which says "reduce my order by 10", then: 1. First seller's order to sell 90 matches your order to buy 100; you buy 90, and your order is reduced to one to buy 10 2. Your modify message reduces your order of 10 to 0 3. Second seller's order to sell 90 arrives, but has nothing to match with You have successfully bought 90 shares, well done. If the message to reduce your order is a nice safe idempotent one which says "change my order to 90", then: 1. First seller's order to sell 90 matches your order to buy 100; you buy 90, and your order is reduced to one to buy 10 2. Your modify message increases your order of 10 to 90 3. Second seller's order to sell 90 matches your order to buy 90; you buy 90, and your order is reduced to 0 You have bought 180 shares. Oh dear. This is not hypothetical. More than one new exchange has launched with a protocol where orders are modified to a target amount, rather than by a target delta, and changed it some time later, after their users got themselves in a pickle. You can do a bit better by making the modify message a compare-and-set, so it only changes the quantity to 90 if it is currently 100. In that situation, the modify will fail, and the second order will sell you 10 shares. That's still not as good as the non-idempotent message. > (I suspect you meant “safe” in a different sense, but I couldn't resist.) The moral of this story is that computer scientists should not be allowed to use the word "safe"!
- ComputerGuru 9y agoIt’s funny because if you read what they wrote, they’re fully aware of the difference between the two (since they reference the HTTP RFC definition of the idempotency of PUT and DELETE).
- jholman 9y agoI disagree that this is common the world of software, and I disagree that the WP article that you linked makes that claim. I humbly suggest that you might benefit from reading that article more carefully.
- dylanpyle 9y agoYou're right, I meant to summarize more along the lines that calling something multiple times doesn't cause more than one set of side effects. Unfortunately too late to edit by the time I re-read it!
- lawn 9y agoI wonder what would have happened if you gave a short counter example.
- js2 9y agoThat difference is somewhat subtle and I had to read the description in the sibling comment to understand it. I would have welcomed a correction from somone I was interviewing. On a side note, the founders of Google once tried to explain recursion and idempotence to Terry Gross on NPR. It's pretty amusing. It starts at 13:45 into the interview here: http://www.npr.org/2003/10/14/167643282/google-founders-larry-page-and-sergey-brin-part-2 http://www.npr.org/2003/10/14/167643282/google-founders-larr...