Rolling changes back is an important aspect of Reactive C# because it makes reactive code more declarative.

Consider this reactive method:
void PinkWhenDoesntMatch(TextBox txt, Regex rgx)
    if (!rgx.IsMatch(txt.Text))
        // it is a data binding, not a plain assignment:
        txt.Background = Brushes.LightPink;
Here is the original intent of this code:
the textbox must be painted pink when its text doesn't match the regular expression
This human description implies that
the textbox must not be painted pink when its text matches the regular expression
Reactive C# honors this implication: when a reactive statement is deactivated, it rolls its state changes back. This feature makes it is easier for developers to express user requirements for program behavior in Reactive C#.

Not all cases are supported, because the Transactional Memory problem is hard to solve in general (Microsoft tried). For example, if a reactive code calls a non-pure function (e.g. Console.WriteLine) it is unable to roll the side effects back because the function is a black box. But a reactive assignment statement is able to restore the original value of the left-hand side expression.

Last edited Feb 14, 2011 at 8:56 PM by reactive, version 2


No comments yet.