A side effect is an observable change or external action produced by a function in addition to its return value. Functions may print, modify data, send information over a network, or change system state while performing their main calculation. section 3.1.3 section 3.2.7
Manage side effects deliberately:
- Make side effects intentional; unexpected global-variable changes can affect unrelated functionality. section 3.2.7
- Release resources promptly by closing files and database connections when they are no longer needed. section 3.2.7
- Watch for mutations through function arguments: a function can alter an external list when both names reference the same object. section 3.2.7
Mutating input versus working on a copy
A total(values, new_value) function that appends directly to values returns 10 but changes [1, 2, 3] into [1, 2, 3, 4]. A better_total function copies the list first, returns the same total, and leaves the original list unchanged. section 3.2.7























