Self-documentation
Pure functions have another advantage. Since everything the function needs to work with is given to it through its parameters, with no kind of hidden dependency whatsoever, when you read its source code, you have all you need to understand the function's objective.
An extra advantage: knowing that a function doesn't access anything beyond its parameters makes you more confident in using it, since you won't be accidentally producing a side effect; the only thing the function will accomplish is what you already learned through its documentation.
Unit tests (which we'll be covering in the next section) also work as documentation, because they provide examples of what the function returns when given certain arguments. Most ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access