Ok so this is a personal investigation of how reactive programming can be better embedded in imperative languages in general. I have conducted such an investigation for JavaScript already with interesting results, but focusing solely on JavaScript and its conventions might be a bit limiting as I feel results can be achieved that are more generally applicable.
A lot of modern programs work with reactive values or observables, i.e. values that change over time (number of clicks on a button, time of a timer, position of the mouse cursor, etc.). These values need to get processed, combined with other observables, etc.
Imagine a simple use case: a text input with a word count display underneath. You can specify this with a simple pseudo-code as follows:
input = <the text user types>
count = input.split(' ').size()
This code is declerative: values of input
change as the user types more stuff, and values of count
must be updated accordingly, so that the equality on the second line always holds. In other words, here we are NOT instructing the computer to do a specific processing, we are just describing how the end result (count
) should be.
Unfortunately, most commonly used programming languages are not declerative. They are centered around the idea of instructing the computer to conduct specific computations immediately, in other words, they are imperative. Fortunately, most of these languages support