FunHop : What Are These Side Effects?


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


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s