5.2 - Encapsulation

Encapsulation is a technique where we restrict access to some local state to only be accessible from within its local scope, effectively protecting it from any access from outside that scope. So, what does this have to do with side effects? It affects one particular special case of side effects: mutable state. Consider one of our first examples, a sum of all the numbers in an array: let sum = function(array){ let result = 0; for(let i = 0; i < array....

5.3 - Idempotence

In some cases, we can’t avoid the side effects, but we can structure them in such a way to reduce their impact on the overall structure of the system. In other words, we still get to have the side effects, but the extent at which they get to exhibit their behavior is constrained in such a way that makes our lives easier. Idempotence is one such constraint that can help us turn what would otherwise be an unmanageable imperative algorithm into a manageable one....

5.4 - Semantically Insignificant Side Effects

And finally there’s that approach where we deal with some side effects by ignoring them because we decided that they are not important. Intuitively, this just sounds plain wrong, doesn’t it? We don’t like something about the code, why don’t we pretend it doesn’t exist! Except that we’re already doing that anyway, just scroll back to the chapter on Inherent impurities to refresh your memory. We are ignoring the fact that every code that runs on an actual physical computer has to obey the basic laws of nature: it takes time to run, space to store the data, emits heat, and so on....