
How Reactive Programming Differs From Procedural Programming 186
Nerval's Lobster writes "A recent post on Reactive Programming triggered discussions about what is and isn't considered Reactive Logic. In fact, many have already discovered that Reactive Programming can help improve quality and transparency, reduce programming time and decrease maintenance. But for others, it raises questions like: How does Reactive differ from conventional event-oriented programming? Isn't Reactive just another form of triggers? What kind of an improvement in coding can you expect using Reactive and why? So to help clear things up, columnist and Espresso Logic CTO Val Huber offers a real-life example that he claims will show the power and long-term advantages Reactive offers. 'In this scenario, we'll compare what it takes to implement business logic using Reactive Programming versus two different conventional procedural Programming models: Java with Hibernate and MySQL triggers,' he writes. 'In conclusion, Reactive appears to be a very promising technology for reducing delivery times, while improving system quality. And no doubt this discussion may raise other questions on extensibility and performance for Reactive Programming.' Do you agree?"
Does it handle dupes? (Score:4, Informative)
How does RP handle dupes [slashdot.org]?
I know I put in my $0.02 previously, so I won't bother again.
what "Reactive Programming" really is (Score:4, Informative)
from what i've read on wikipedia, [wikipedia.org] "Reactive Programming" is really just function as a variable with caching.
example:
c = 5 // outputs 9 // outputs 10
b = 4
a = b + c
print(a)
c = 6
print(a)
this isnt rocket surgery
Re:I thought that we were supposed to be pro-activ (Score:4, Informative)
Ok, there are a lot of people commenting on this below who have absolutely no idea what reactive programming is about. So I'll try to clear it up a bit.
Reactive programming is not polling.
If you call a function and wait for it to return a result, you aren't doing reactive programming.
If you are working in a REPL or command-line environment, and you have to type a command every time you want to obtain a result, your system is not reactive.
Reactive programming is not events and triggers. Well... let's say it this way: reactive programming is to events/triggers as writing in [C/C++/Java/C#/Haskell/etc.] is to writing in assembly. In other words, you really could do the same exact thing with events or triggers than you can do with reactive programming. But events and triggers are very basic compared to what is meant by reactive programming.
Events and triggers are typically used when a little reactivity is needed. When you build your system around reactivity, using events and triggers quickly becomes inefficient and you need something built for the task. You would pick a reactive programming language or framework for such a complex job, just like (most of) you would choose high-level languages and frameworks over assembly for building a social media website.
Reactive programming isn't an agile framework. It's not some new way of describing object-oriented programming. And it's not the right tool for every job, but for some jobs, it's the perfect tool.
Re:I thought that we were supposed to be pro-activ (Score:5, Informative)
The point of new paradigms in programming languages is to make the complexity of the expression match the complexity of the idea being expressed, not the complexity of the (platform specific) implementation.
Crappy illustration:
C++ - Event-trigger
// event
// trigger
// actual code you want to get around to actually writing
// some routine that modifies a continuously
vector triggers;
void add_trigger(Trigger * t);
void reactive_variable::modify_value(int new_value)
{
this.value = new_value;
for (i = triggers.begin(); i != triggers.end(); i++){
i.react(new_value);
}
}
int main()
{
reactive_variable a;
Trigger *b = new Trigger(COPY_VAR);
a.add_trigger(b);
Trigger *c = new Trigger(ADD_VAR, 1);
a.add_trigger(c);
a.modify_value(2);
enter_event_loop();
return 0;
}
Incomplete, inelegant and probably buggy, but you get the picture.
Verilog - Reactive
assign b = a;
assign c = a+1;
inital a = 2;
always @(posedge clk)
a = count(input);
Easy to understand whats going on and spot errors. 'b' will always equal 'a' and 'c' will always be one more.