Reactive Programming – the New Programming Paradigm?

I am on the last lap of my master thesis, which has the nice title „Tool Support for Reactive Programming“. But what exactly is reactive programming (RP)? It basically just describes systems which are reactive in the sense that they directly adapt to changing inputs or a changing environment in general. If an input value changes, reactive systems directly re-compute the depending output values, so that the outputs always reflect the current inputs. Informally, one can compare RP with spreadsheet programs like Microsoft Excel. If a value in a cell is changed, all values which depend on that cell are directly re-computed and updated. That is pretty much the idea behind RP.

Now there are multiple ways to implement such reactive systems. For years this has basically been done with the observer pattern, which has various drawbacks. Just to name a few: It is error-prone, update triggering code is scattered throughout the system, it is not possible to compose different reactions, there is no separation of concerns, there is a whole lot of boilerplate code etc. Hence, better solutions like event-driven programming (EDP) or aspect-oriented programming (AOP) have been developed. These solutions clearly have their advantages over the observer pattern, but some problems still remain. For instance, dependencies have to be encoded manually and event handlers still have to implement the updates explicitely.

So how cool would it be to have a language which directly supports time-changing values, which are automatically updated once a depending value changes? That is indeed a great idea and it is exactly the idea behind RP or – more specifically – behind reactive languages. With the help of reactive languages, the output of the following example would be 6, because line 3 would rather be interpreted as a constraint instead of an assignment.

val a = 1
var b = 1
val c = a + b
b = 5
println(c)

I think that this relatively new programming paradigm has a good potential to change the way we develop software. But given the fact that even EDP and AOP have not really reached the point of widesprad usage, it will probably still take years until reactive languages are commonly used. One big problem besides of the fact that the paradigm is plain unknown to many developers is that there is no proper tool support – especially in relation to the debugging process. In my master thesis, I developed one step towards a better RP debugging experience by developing a specialised debugger for RP. Come back soon if you want to know more about the thesis – it will probably also be published here.

If you would like to know more about RP in general and would like to play with it, have a look at the following projects:

  • [for the history fanatics the first reactive language] Fran (functional reactive animation): reactive Haskell library
  • FrTime: reactive addon for Racket / Scheme
  • Flapjax: reactive addon for JavaScript
  • Scala.React: reactive addon for Scala from the author of Scala
  • REScala: reactive addon for Scala, which fully integrates into OO applications

3 Gedanken zu „Reactive Programming – the New Programming Paradigm?“

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert