5

I've read about the basic idea of reactive programming as having variables that change over time based on their source value expression. I've even implemented this using Expressions. But then I look at Microsoft's Reactive Extensions (Rx) and see something totally different. Where are the variables that self-update over time? There are none to be seen. Just some fancy way of enumerating through event arguments.

So my question is: how "reactive" is Rx really? Is the functionality that we're seeing there now a precursor to what's to come? Or is Microsoft carelessly throwing around a buzz word? Or am I just totally missing the point (in which case I'd like you to explain how)?

EDIT: I got some great answers already with descriptions of Rx, in addition the question being closed. :( But I'm still hoping to hear more along the lines of:

  1. In what sense is Rx "reactive"? I thought that self-updating variables were central to the idea but Rx doesn't supply these. LINQ-to-Events seems like a better name for Rx. I'm starting to think that maybe Microsoft misused the word "reactive" in applying it to Rx.
  2. In what way might the current Rx functionality be a precursor to self-updating variables? I've implemented such functionality and did not notice anything useful from Rx for this purpose.
HappyNomad
  • 4,092
  • 3
  • 31
  • 52
  • 'variables' imply keeping state. Rx is a high level abstraction to compose state-machines without explicitly keeping track of state. – Asti Feb 08 '13 at 08:22
  • @Asti - Please suggest a better term to use. – HappyNomad Feb 08 '13 at 20:57
  • 1
    I don't see much subjectivity in this question - seems to be asking a very legitimate question. The tone errs a little close to “______ sucks, am I right?” but I don't think that's the intent. – JDB still remembers Monica Feb 08 '13 at 21:06
  • @JerKimball - I'm actually wasn't trying to ask for descriptions of Rx, although I appreciate the effort. Rather, I'd like to know how Rx relates to reactive programming. – HappyNomad Feb 08 '13 at 21:13
  • @Cyborgx37 - Right. I see Rx is useful but I don't see how it is "reactive". – HappyNomad Feb 08 '13 at 21:25
  • @HappyNomad http://stackoverflow.com/questions/1028250/what-is-functional-reactive-programming – Asti Feb 09 '13 at 04:29
  • @Asti - I already saw that, but thanks anyway. I am still planning to read through the great reading material found in Conal's answer. So I guess this means you don't know what term to use instead of 'variables'... which is fine since I'll find out later. – HappyNomad Feb 09 '13 at 05:03

3 Answers3

7

"Reactive" might be more of a buzz-word than anything, although it does tie in nicely to another language concept called "Functional Reactive Programming"...

At any rate, what Rx "is" has been answered by far more intelligent people than myself, but I'll give it a go:

  • In the beginning, there were things; these things had shape, and were called POCOs

  • Collections of these POCOs formed, and thus they were named IEnumerable<T>

  • "But what of events" the people moaned and wailed, "They do not fit nicely into collections and groups! We must create strange and alien-feeling call and response handlers to cope with them!"

  • It was then that TheErik, TheBart and others looked at these strange events and thought "Hey, we can make them act like POCOs, for they are but the mirror image of the IEnumerable<T>!"

  • This was the birth of the IObservable<T>, the dual of the IEnumerable<T> (for the stream "pushes" information to the observer, instead of the observer "pulling" items out)

  • Then I got sick of writing in "Genesis Mode", and those really smart folks bundled up the same monadic query logic that formed LINQ along with the ability to "time-travel" with ISchedulers and called it "Rx"

JerKimball
  • 15,805
  • 3
  • 38
  • 54
2

Oh boy! Okay. I think that the main issue here is vocabulary. Rx is often described as a Linq to "Event" or something of the like, and is implemented with something called an IObservable.

I am sure everyone who has just started out in Rx will have fallen for the same pitfalls. When we see the word 'event' we think of the keyword event/event handler etc etc... However in the context of Rx, an event is more general than that. It is anything that happens asynchronously, most likely on another thread. Now of course, one type of event is the .net event, and there is some value in using the Observable.FromEventPattern factory method for creating event handler-> IObservables, as the life cycle of them is represented as a IDisposable (but more about that later).

Another usage of Rx is data parallelism, in that it overlaps heavily with TPL Data Flow. A typical pattern I use for a large data parallel piece of work is to convert it to an Rx IObservable and then apply the processing/threading behaviors as monads.

With respect to the fancy part, IObservable has a Linq provider, which allows you to use Linq to process asynchronous processes asynchronously (for example Speculative execution using the TPL).

Finally IObservable is an unfortunate name as it leads most people to confuse it with the idea of INPC as it looks similar to ObservableCollection. I assure you its not.

Community
  • 1
  • 1
Aron
  • 14,744
  • 3
  • 26
  • 58
0

Reactive programming is based around "data flows" and "propagation of change."

There are various ways of representing this. The Rx Framework is basically revisiting the traditional event based paradigm as a streaming representation of events, and providing operations around that.

Reed Copsey
  • 522,342
  • 70
  • 1,092
  • 1,340
  • Please see the question's edit and consider expanding upon your answer. Also, please vote to reopen it since it's been closed. – HappyNomad Feb 08 '13 at 21:04
  • 1
    @HappyNomad As I said - reactive isn't *necessarily* about "self updating variables" as much as "data flows" and "propogation of change". Rx tries to address other aspects of reactive programming. – Reed Copsey Feb 08 '13 at 21:59
  • @Reed_Copsey - Thanks. I'll have to read up on those concepts, probably on Wikipedia, when I have a chance. Still would be nice to see a bit more detail here on SO, though. – HappyNomad Feb 09 '13 at 00:09