Side Effects
1 min readMay 1, 2018
A function or expression is said to have a side effect:
- If it modifies some state
- Has an observable interaction with calling functions or the outside world
For example, a particular function might:
- Modify a global variable or static variable
- Modify one of its arguments
- Raise an exception
- Write data to a display or file
- Read data
- Call other side-effecting functions
Simply, side effect = changing something somewhere.
Problems with Side Effects
In the presence of side effects, a program’s behavior may depend on history i.e., the order of evaluation.
Understanding and debugging a function with side effects requires knowledge about the context and its possible histories.