Skip to main content
13 events
when toggle format what by license comment
Feb 23, 2018 at 20:02 history edited Robert Harvey CC BY-SA 3.0
deleted 11 characters in body
Feb 23, 2018 at 20:01 comment added JimmyJames @JörgWMittag I'm not sure I buy that GET is pure. Yes, it has no side effects but it can definitely depend on hidden information i.e. the result is not purely (see what I did there) dependent on the input.
Feb 23, 2018 at 19:51 comment added Jörg W Mittag Early web applications often violated those guarantees, by e.g. performing operations such as ordering something from a store or deleting a user account using GET requests, which broke in rather serious ways, when "web accelerators" (proxies or browser background processes that transparently pre-fetched links from websites the user was currently browsing) were invented.
Feb 23, 2018 at 19:45 comment added Jörg W Mittag The most widely-known application of this is HTTP, where POST makes no guarantees, PUT is guaranteed to be idempotent, and GET and HEAD are guaranteed to be idempotent and pure, which is extremely important for both caching and reliability (idempotency meaning that I can safely retry an operation without checking whether it had any side-effects or not, purity meaning that I can safely cache an operation, and both meaning that I can safely pre-fetch operations for caching).
Feb 23, 2018 at 19:41 comment added Jules ... i.e. if a function f(x, S) -> (x', S') is interpreted as accepting parameter x with system state on entry of S, returning x' and modifying the system state to S', then it is idempotent iff f(f(x,S)) also yields (x', S'), which you should be able to see agrees with both Jörg's definition and the usual way of understanding the word in software engineering.
Feb 23, 2018 at 19:38 comment added Jörg W Mittag Yes, I am: I am passing 16 both times. If sqrt were idempotent, then the result of sqrt(16) and sqrt(sqrt(16)) should be the same. Your "pure/idempotent" suggests that those two concepts are the same or at least closely related, when in fact, they are orthogonal: I give two examples of functions/subroutines that are pure but not idempotent, and idempotent but not pure. (In fact, the idea of idempotency, at least as commonly applied in programming, isn't very interesting without side-effects.) abs is an example of a function that is both pure and idempotent.
Feb 23, 2018 at 19:36 comment added Jules @RobertHarvey - Jörg is using the mathematical definition of Idempotence (see the first bullet point in the lead section), not the common software engineering one, which can be seen as equivalent if the state of the system is an additional implicit parameter to the function.
Feb 23, 2018 at 18:54 comment added Robert Harvey Your sqrt example doesn't make any sense. Nobody disagrees that those two calls return a different result, but you're not passing in the same value, are you?
Feb 23, 2018 at 18:34 comment added Jörg W Mittag Note: purity is not the same as idempotency. idempotency says that f(f(x) == f(x) FORALL x, or in other words: the result of executing a subroutine multiple times is the same as executing it once. sqrt is pure, but not idempotent: sqrt(sqrt(16)) is not the same as sqrt(16). Conversely, a subroutine that deletes a particular file is idempotent (if you execute it once, the result is that the file is gone, if you execute it multiple times, the file is still gone) but clearly not pure.
Feb 23, 2018 at 18:18 comment added Yatrix That's where I was leaning too, but I'm new to this way of thinking. Thank you.
Feb 23, 2018 at 18:17 vote accept Yatrix
Feb 23, 2018 at 18:11 history edited Robert Harvey CC BY-SA 3.0
added 74 characters in body
Feb 23, 2018 at 17:57 history answered Robert Harvey CC BY-SA 3.0