Timeline for What do you call a function where the same input will always return the same output, but also has side effects?
Current License: CC BY-SA 4.0
33 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Nov 1, 2018 at 10:04 | comment | added | Aphton | Fine gentlemen, allow me to give proposals. Let's call it either dirty-, kinky- or naughty function | |
| Nov 1, 2018 at 6:34 | history | edited | m0meni | CC BY-SA 4.0 | edited title |
| Mar 24, 2017 at 7:16 | comment | added | bikeman868 | If a function has side effects that would be surprising given its name I would call it "broken". | |
| Mar 23, 2017 at 8:56 | review | Close votes | |||
| Mar 28, 2017 at 3:02 | |||||
| Mar 23, 2017 at 3:59 | comment | added | Andres F. | @KeremBaydoğan Your definitions are non-standard. Your definitions of pure and deterministic are puzzling. Also, what is a "const function"? The closest general concept I can think of is constant function, which is not what you described. | |
| Dec 30, 2016 at 7:23 | review | Close votes | |||
| Jan 5, 2017 at 3:02 | |||||
| May 24, 2016 at 8:43 | comment | added | Kerem Baydoğan | a pure function is one which do not affect anything outside of it's scope. a const function is one which do not read any data other than variables that are passed to it. a deterministic function is one which always give the same output for a given input. an optimized compiler could choose not to call a pure function in a short-circuit evaluated if statement because it has no side-effect. an optimized compiler could cache return value of a const function for a given input and use it in place of function calls because it is constant. a deterministic function gives you peace of mind. | |
| May 10, 2016 at 18:36 | answer | added | sacundim | timeline score: 1 | |
| May 5, 2016 at 9:45 | history | tweeted | twitter.com/StackProgrammer/status/728158747542081536 | ||
| May 2, 2016 at 13:22 | comment | added | njzk2 | @MSalters good precision. In my current world functions tend to be stateless but belong to stateful object, in which case one could argue that the state of the object containing the function is part of the argument | |
| May 2, 2016 at 13:17 | answer | added | candied_orange | timeline score: 23 | |
| May 2, 2016 at 10:44 | comment | added | MSalters | @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). | |
| May 2, 2016 at 9:14 | history | protected | gnat | ||
| May 2, 2016 at 9:00 | answer | added | Ben Hutchison | timeline score: -1 | |
| May 2, 2016 at 8:19 | comment | added | Erik | I'd argue that such a function would be called "doing too much", since it has both a relevant return value AND a side effect and is almost certainly doing two things. | |
| May 2, 2016 at 2:25 | comment | added | Kevin Krumwiede | To be more precise, a pure function has no visible side effects. I'd argue that "visible" should be interpreted in this context as visible within the API that the function belongs to. If writing to a database has no visible effect, then this function could be considered pure. On the other hand, if it has no visible effect, then why would you do it? Perhaps for debugging... | |
| May 1, 2016 at 19:24 | comment | added | njzk2 | Something that always give the same output for a given input is called deterministic. | |
| May 1, 2016 at 18:54 | comment | added | Jimmy T. | @Voo If the value is not in the cache there is a side effect otherwise not. That's not random. | |
| May 1, 2016 at 18:52 | comment | added | Voo | @Jimmy A caching layer that randomly ignores side effects seems like a downright horrible idea. | |
| May 1, 2016 at 18:47 | comment | added | Jimmy T. | @Voo Caching is one of those cases where you get the same result but can have a side effect. | |
| May 1, 2016 at 17:36 | comment | added | Voo | What would be the point of having a name for such a function? The reason we care about purity is because it allows us specific optimisations, but why would you want to distinguish between functions with side-effects whose inputs may depend on global state and functions with side-effects? There is just no practical use here. | |
| May 1, 2016 at 12:32 | answer | added | Jon Hanna | timeline score: 9 | |
| May 1, 2016 at 9:40 | comment | added | Bakuriu | 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". | |
| May 1, 2016 at 3:54 | comment | added | m0meni | @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. | |
| May 1, 2016 at 3:16 | comment | added | Ross Patterson | "Not a pure function". | |
| Apr 30, 2016 at 23:02 | answer | added | user470365 | timeline score: 3 | |
| Apr 30, 2016 at 22:37 | vote | accept | m0meni | ||
| Apr 30, 2016 at 22:37 | vote | accept | m0meni | ||
| Apr 30, 2016 at 22:37 | |||||
| Apr 30, 2016 at 22:21 | answer | added | Andres F. | timeline score: 86 | |
| Apr 30, 2016 at 21:44 | review | Close votes | |||
| May 5, 2016 at 3:01 | |||||
| Apr 30, 2016 at 21:37 | vote | accept | m0meni | ||
| Apr 30, 2016 at 22:37 | |||||
| Apr 30, 2016 at 21:36 | answer | added | DeadMG | timeline score: 2 | |
| Apr 30, 2016 at 21:21 | history | asked | m0meni | CC BY-SA 3.0 |