Slashdot is powered by your submissions, so send in your scoop

 



Forgot your password?
typodupeerror
Programming

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?"
This discussion has been archived. No new comments can be posted.

How Reactive Programming Differs From Procedural Programming

Comments Filter:
  • by istartedi ( 132515 ) on Monday January 13, 2014 @08:42PM (#45946127) Journal

    How does RP handle dupes [slashdot.org]?

    I know I put in my $0.02 previously, so I won't bother again.

  • by Gravis Zero ( 934156 ) on Monday January 13, 2014 @10:06PM (#45946749)

    from what i've read on wikipedia, [wikipedia.org] "Reactive Programming" is really just function as a variable with caching.

    example:

    c = 5
    b = 4
    a = b + c
    print(a) // outputs 9
    c = 6
    print(a) // outputs 10

    this isnt rocket surgery

  • by bondsbw ( 888959 ) on Monday January 13, 2014 @11:59PM (#45947583)

    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.

  • by metamarmoset ( 2728667 ) on Tuesday January 14, 2014 @08:33AM (#45949649)

    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
    vector triggers;

    void add_trigger(Trigger * t);

    void reactive_variable::modify_value(int new_value)
    {
    // event
    this.value = new_value;
    // trigger
    for (i = triggers.begin(); i != triggers.end(); i++){
    i.react(new_value);
    }
    }

    // actual code you want to get around to actually writing
    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(); // some routine that modifies a continuously

    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.

Nothing succeeds like success. -- Alexandre Dumas

Working...