Side Effects

In notebook:
FrontEndMasters Functional light
Created at:
Functional Programming JavaScript Fundamentals
That is not the direct result of my program. That changes indirectly the state of the program (not through the result).

We have to remove as much as possible side effects. Haskell language doesn't even let you do side effects.

Sometimes we have to cheat. We need input and output to get usefulness of our program. 
But it's good to be intentional about where you expect to have a side effect (input-output). 

 Closure: there's a tension about side effects. You can create a closure so the results is not the same each time you run your function. 

Many functional programmers actually use impure functions. But they never leave them publicly exposed. This is how make it functional. Wrap them in an outside function that hides the impure functions. 

The problem with impure functions is that they make the programs harder to reason about. 

Shows how he turned an impure function to pure function by wrapping it with another function that receives all parameters as argument that are changed by the impure function. 
We could also refactor the original impure function, but wrapping is more common.