by hellofunk · 9y ago · 0 comments
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.
One notable example: Stripe's "idempotency keys": https://stripe.com/blog/idempotency
echo hello
This is side-effectful, but idempotent: echo hello >world
This is side-effectful and not idempotent: echo hello >>worldIn the hello world example, I guess we are considering 'echo' as the function. If then if we consider stdout and echo's args to be the same, echo will be idempotent.
However, stdout and command args are pretty different things on any system I know. If we care about things like command line history, then clearly 'echo hello world' is not idempotent.
About the only side effect free operation at a blank line terminal prompt is _probably_ hitting enter or ctrl c. Or ‘#something<Enter>’
But your idempotency examples are spot on.
Basically, idempotency is a very useful concept. Side effect free isn’t.
I posit that you understand perfectly well what i was getting at! If it helps, imagine that you are spawning a fresh shell to execute each command line, through system(3) or some such.
(I suspect you meant “safe” in a different sense, but I couldn't resist.)
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-larr...