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*

16
  • 93
    "Not a pure function". Commented May 1, 2016 at 3:16
  • 2
    @RossPatterson that's what I thought as well, but by asking I learned about referential transparency so I'm glad I didn't keep it to myself. Commented May 1, 2016 at 3:54
  • 9
    If writeToDatabase fails it could trigger an exception thus making your second add function produce an exception sometimes even if called with the same arguments that before didn't have problems... most of the time having side effects introduces this kind of error-related conditions that break "input-output purity". Commented May 1, 2016 at 9:40
  • 28
    Something that always give the same output for a given input is called deterministic. Commented May 1, 2016 at 19:24
  • 2
    @njzk2: True, but it's also stateless. A stateful deterministic function may not give the same output for every input. Example: F(x) is defined to return true if it's called with the same argument as the previous call. Clearly with the sequence {1,2,2} => {undefined, false, true} this is deterministic, yet it gives different outputs for F(2). Commented May 2, 2016 at 10:44