4 ms·
Among non-pure functions I can think of two interesting subclasses: 1. A functions with no side effects which (possibly) returns different values each time it'
by augustk 3y ago
Among non-pure functions I can think of two interesting subclasses:
1. A functions with no side effects which (possibly) returns different values each time it's called, for instance a function which reads a global variable and returns its value
2. A function with side effects while running but which leaves the state of the program and its environment unaltered once it has returned, for instance a function which displays a dialog window and returns when the user clicks a button in it.
Are there any names for these classes of functions?
- Leftium 3y agoI think both #1 and #2 have side effects (interactions with external mutable state.) 1. The side effect here is an input, and affects the output value of the function. 2. The side effect here is an output (or "action"). Displaying a dialog window mutated something in the external state of the program. Technically, I think "side effects" are undesired interactions. So #2 might just be an "effect" since it is presumably desired. So maybe: 1. Side effect 2. Effect