Reactive programming

Reactive Programming seems to be the rage nowadays (as observed in blogs and newsletter). Out of curiosity I looked it up and was impressed with what it is capable of. Turns out that this is a declarative approach which allow code to react to changes in referenced values.

Let’s understand it from the perspective of a spread sheet. Lets say cell A1 has the formula “=B1+C1”. Now typically we expect that if we change the value in B1 or C1 then the value of cell A1 will be updated automatically.

Keeping this example in mind now lets see how  this can work in programming world. Lets say we have an expression that says A = B + C. When this expression is executed in our code then the value of A is updated whenever this expression is ‘executed’. Once this is done the value of B can be changed or the value of C can be changed without reflecting on the value of A. To enforce a ripple effect back to A like we observed for cell A1 in spreadsheet we have to devise elaborate observers / listeners on the values of B and C to update A whenever the value of B or C change. In a real life production environment this simple expression can be replaced with more complex algorithm or data flow and you have a situation which can quickly get out of hand and might be difficult if not impossible to debug.

In reactive programming we react to changes. So in the above situation the value of variable A will be updated as and when the value of B or C changes.

This concept has been well explained in a dzone article.

Leave a Reply

Your email address will not be published. Required fields are marked *