Jump to content

Reactive programming

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Robwe (talk | contribs) at 11:39, 17 July 2007 (Gave a description of reactive programming). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

Reactive programming is a programming paradigm oriented around interactive data flows. This means that it should be possible to express interactive data flows with ease in the programming languages used.

For example, in an imperative programming setting, would mean that a is beeing assigned the result of in the instant the expression is evaluated. In reactive programming it could instead mean that we set up a dynamic data-flow from and to . Whenever the value of or is changed, then is automatically changed also.


Evaluation models of RP

Evaluation of FRP programs is not necessarily based on how stack based programming languages are evaluated. Instead, when some data is changed, the change is propagated to all data that is derrived partially or completley from the data that was changed. This change propagation could be achieved in a number of ways, where perhaps the most natural way is an invalidate/lazy-revalidate scheme.

One reason it would be problematic to just naively propagate a changes using a stack, is because of potential exponential update complexity if the data structure has a certain shape. One such shape can be described as "repeated diamonds shape", and has the following structure: An->Bn->An+1, An->Cn->An+1, where n=1,2...

One inherent problem for RP is that most computations that would be evaluated and forgotten in a normal programming language, needs to be represented in the memory as data-structures. This could potentially make RP memory consuming. However, research on what is called Lowering, could potentially overcome this problem. [1]


Reactive Imperative Programming

It is possible to fuse reactive programming with ordinary imperative programming. In such a paradigm, there would be imperative programs operating upon reactive data structures. Such a setup is analogous to constraint imperative programming, but where constraint imperative programming manages bi-directional constraints, reactive imperative programming just manages a-cyclic data-flows. Reactive imperative programming could be seen as the smaller brother of constraint imperative programming.


Object Oriented Reactive Programming (OORP)

OORP is a combination of object oriented programming and functional reactive programming. Perhaps the most natural way to make such a combination is as follows: Instead of methods and fields, objects have reactions that automatically reevaluate when the other reactions they depend on have been modified.

If an OORP programming language maintains its imperative methods, it would also fall under the category of imperative reactive programming.


Functional Reactive Programming

Functional reactive programming is reactive programming in the settings of functional programming langauges.