Explain Reactive Programming Like I'm Five

johnpaulada profile image John Paul Ada Aug 13, 2017

I'm still having problems comprehending Reactive Programming. Thanks in advance for the help. :)

markdown cheatsheet

Reactive programming is like the infamous "marble course" we all loved to play with as kids:

marble course

Instead of dictating what your code should do RIGHT NOW (procedural programming), you define what may happen in response to a certain set of events, like where you may have several "entry pipes" in your marble course!.

If you've ever made a formula in Excel, you've done reactive programming.

If you put =A1+B1 in the cell C1, you're saying you want C1 to be updated every time A1 or B1 is updated. That's also what you do in reactive programming.

Or, in other words: this value is based on changes from these other values.

Imagine walking into coffee shop and ordering a cappuccino. The barista takes your order and starts making the coffee. Other customers wait patiently behind you in line till your coffee is prepared and you pay. The barista then deals with the next customer. This is imperative style coding.

Now, imagine walking into a coffee shop and ordering a cappuccino. The barista takes your order and hands you a token. He shouts to his minions saying "Token 42, Cappuccino, no sugar". You are asked to wait comfortably on a couch. The barista then deals with the next customer. Whenever your coffee is ready, he shouts "Token 42, Cappuccino, no sugar, ready!". You show your token, pick up the coffee and walk out. Other customers do the same. That's reactive programming. You reacted to a set of events and didn't wait till a process was complete.