News for hackers. Stuff that matters.
Re:Functional programming in C++ (2012) by hawk_ on Tuesday December 29, 2020 @01:08AM (#25567218)
All pure functions are idempotent but not all idempotent functions are pure. It has nothing to do with the domain/range of the function.
Re:Functional programming in C++ (2012) by curryhoward on Tuesday December 29, 2020 @02:15AM (#25567531)
You are correct in that there is a definition of idempotence that agrees with you, but you are wrong to correct the parent comment, because the most common mathematical definition of idempotence of functions agrees with them (and not you).

There are multiple definitions of idempotence, used even within computer science, and neither of you seem to be aware of the definition used by the other. The common mathematical definition of an idempotent function is that f(f(x)) = f(x) for all x. But in computer science there is another common definition which involves side effects not being repeated (that is, `f(); f();` is the same as `f();`).

Re:Functional programming in C++ (2012) by jcelerier on Tuesday December 29, 2020 @04:56AM (#25568326)
> But in computer science there is another common definition which involves side effects not being repeated (that is, `f(); f();` is the same as `f();`).

where have you ever seen that definition ?!

Re:Functional programming in C++ (2012) by halter73 on Tuesday December 29, 2020 @05:06AM (#25568380)
> in imperative programming, a subroutine with side effects is idempotent if the system state remains the same after one or several calls

https://en.wikipedia.org/wiki/Idempotence#Computer_science_m...

Re:Functional programming in C++ (2012) by thewakalix on Tuesday December 29, 2020 @06:02AM (#25568666)
It’s used commonly when working with unreliable communication (e.g. networking). For example, if you make a request but you don’t get a response, either the request or the response might have failed to send. It’s convenient if you don’t need to determine which case occurred; idempotent functions free you from worrying about whether the requested action was carried out.