Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

9
  • That's where I was leaning too, but I'm new to this way of thinking. Thank you. Commented Feb 23, 2018 at 18:18
  • 2
    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. Commented Feb 23, 2018 at 18:34
  • 4
    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? Commented Feb 23, 2018 at 18:54
  • @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. Commented Feb 23, 2018 at 19:36
  • 2
    @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. Commented Feb 23, 2018 at 20:01