DEV Community

John Paul Ada
John Paul Ada

Posted on

Explain Reactive Programming Like I'm Five

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

Top comments (6)

Collapse
 
jonasws profile image
Jonas Strømsodd

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!.

Collapse
 
elnawe profile image
Nahuel Jesús Sacchetti

Nailed it!

Collapse
 
johnpaulada profile image
John Paul Ada

Awesome! Thanks!

Collapse
 
mohanarpit profile image
Arpit Mohan

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.

Collapse
 
jonstodle profile image
Jon Stødle

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.

Collapse
 
muthuishere profile image
Muthukumaran

Reactive Programming Basics - adding of two numbers
youtu.be/EgWwEakQWjk

dev.to/muthuishere/reactive-progra...