Slashdot Mirror


How Reactive Programming Differs From Procedural Programming

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?"

1 of 186 comments (clear)

  1. Re:I thought that we were supposed to be pro-activ by metamarmoset · · 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
    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.