What is the definition of a "glitch" in the context of Functional Reactive Programming?
I know that in some FRP frameworks "glitches" can occur while in others not. For example RX is not glitch free while ReactFX is glitch free [1].
Could someone give a very simple example demonstrating how and when glitches can occur when using RX and show on the same example how and why the corresponding ReactFX solution is glitch free.
Thanks for reading.
Definition
My (own) favorite definition:
Definition from Scala.Rx:
Example
Consider integer variables
a
,b
. Definesum
andprod
such thatsum := a + b
,prod := a * b
.Let's rewrite this example to JavaFX:
Now let's write a little consistency check:
This code fails with an assertion error on the last line, because:
b
is updated (to 2)sum
is updated (to 3)This is a glitch —
prod
is temporarily inconsistent witha
andb
.Glitch Elimination Using ReactFX
First note that ReactFX is not "glitch free" out of the box, but it gives you tools to eliminate glitches. Unless you take some conscious effort to use them, ReactFX is not more glitch-free than RX (e.g. rxJava).
The techniques to eliminate glitches in ReactFX rely on the fact that event propagation is synchronous. On the other hand, event propagation in RX is always asynchronous, thus these techniques cannot be implemented in an RX system.
In the example above, we want to defer listener notifications until both
sum
andprod
have been updated. This is how to achieve this with ReactFX: