FunHop is imagined as a series which allows us to gradually hop into the realms of Functional Programming. Our vehicle for the journey is going to be Scala but the fundamentals are applicable across languages.
In this episode we would try to decipher Side Effects. We keep hearing that pure functions are the ones where there are NO side effects. Let us begin with an example.
Do you see any side effect in this code?
If you guessed that it is using var instead of val, we are mutating thus causing a side effect then you are wrong. Ok, a hint is that you can read about the Single Responsibility Principle and then come back and answer this one.
As you would notice, the method “add” returns a Money object. However, it also makes a call to updateBankRecords. This doing some operation on the SIDE and is not returning that…
View original post 356 more words