Subsequent calls to the same function with the same input do not return the same value
val x, y fn f assert f(x) == y refute f(x) == y //why?
A function does not return a value
fn f f //what for?
Calling one function impacts the return value of a different function
val x, y fn f, g assert f(x) == y g(x) refute f(x) == y //why?
All of these code samples are pretty strong indicators of a side effect present in function f. They also all suffer from two pretty big problems:
- They are confusing and hard to reason about
- They depend on multiple functions, multiple values, and/or execution sequence, which makes them hard to test
I find these pretty good reasons to be mindful of introducing side effects, and do it only when really necessary.