3 ms·
> side effects are bad How are side effects an inherintly bad thing? They are pretty important in many cases.
by GhostVII 10y ago
> side effects are bad
How are side effects an inherintly bad thing? They are pretty important in many cases.
- jacquesm 10y agoSide effects from functions that modify global state (or importing global state elsewhere) are bad because they increase the complexity of a program in a way that can very rapidly spiral out of control. The operation of a function reading global state is no longer easily predictable and you'll be tracking hard to replicate bugs. Better to have a function rely entirely on its arguments and to output the result as a return value. Side effects that do things such as persisting data or producing output are - for the most part - acceptable, if they are contained in such a way that you move to as much of a 'functional' approach as soon as you can. So reserve your side effects for the edge of your program, keep the rest as side-effect free as you can. Now that was a little long for a bullet point list hence the abbreviated version.