views:

5678

answers:

6

Has anyone had a good look at the new Reactive Framework?

This implementation of "Linq over Events" was apparently distributed with the new Silverlight 3 Toolkit, as a way to manage asynchronous events.

This approach seems to be great at handling events. One could attach an IObserver to mouse events and record them asynchronously into a collection. Then one can iterate over the data with LINQ, and process it accordingly.

Have you used this, and what was your impression? How would a tool like this fit into a 3-tier, distributed world? Are there other interesting applications of the pattern?

A: 

I don't know if it is just me, but this seems like a recipe for disaster.

leppie
The Silverlight article gives some insight into their reasoning. Silverlight does not allow blocking I/O calls, so they needed a better way to manage events.
Robert Harvey
Leppie, knowing you from CP and the projects you've worked on, your opinion means something to me. And yet I'm surprised to hear you say this. To me, it sounds like a clean, declarative way to do events. Why is this a recipe for disaster?
Judah Himango
Relying on events (that possibly may fire out of order) for side-effects, is just one 'little' concern.
leppie
@Robert: perhaps, I am not too familiar with the event model within Silverlight, but like javascript's it will probably be limited.
leppie
@leppie: If you watch Eric's talk on IObservable/IObserver from Lang.NET, you'll see how they address the issue of out-of-order events.
Ryan Riley
Please expand your answer with a reason why you think it's a recipe for disaster.
JohannesH
@JohannesH: see my comment.
leppie
+10  A: 

I looked and it and my first thought was, "damn, this is nice!" I like the all-in-one-place declarative handling of events. Rather than set up a handler over here, handle the event down here, unhook it there, change some mutable state to keep track of things over there -- you get rid of all that. Declarative is good.

I've played with it only twice now, and haven't used it in any real projects, so that part remains to be seen.

Jafar from the Silverlight toolkit team has a great post about it: Introducing Reactive Framework: Linq to Events He says of Rx:

If you glanced quickly you’d miss it altogether but it’s one of the most exciting additions to the .NET framework since Linq.

There's a Channel9 video that goes deep into the Reactive Framework: Expert to Expert: Brian Beckman and Eric Meijer on the Reactive Framework

One thing to keep in mind, it's compiled against the Silverlight dlls, you can't use it in a WinForms or WPF project. There's a WPF version at Microsoft, but it's as yet unreleased. Of course, it will be part of .NET 4 framework.

The name sucks, IMO -- this promises to change the way we deal with asynchronous code; but a name like Linq to Events doesn't hint at this.

Judah Himango
+1 Eric Meijer, used to be one of my favorite teachers :)
Thorarin
I wrote a post about how to get the SL dll running on the .net framework for those who just can't wait to give it a try : http://evain.net/blog/articles/2009/07/30/rebasing-system-reactive-to-the-net-clr
Jb Evain
Cool, thanks JB.
Judah Himango
For the record, of course, there is now RX versions available for .NET 3.5, .NET 4, Silverlight 4, and Javascript.
Judah Himango
+5  A: 

I actually think this is a great thing -

I can see this potentially providing an easier implementation than many places where standard events or IoC are often used. For example, this could dramatically simplify having a flexible logging system. Instead of having to implement some form of IoC, your logging implementations could just implement IObserver<T> and start listening.

Another source of info on this is Paul Batum's blog. He's written an interesting, multi-post series on the Reactive Framework.

Reed Copsey
+9  A: 

Wes and Erik demo'd this to me last year and I was mightily impressed. It is a very slick way to conceptualize events, and I'm excited to try it out. That said, (1) I haven't actually used it to build anything yet, and (2) those guys are way, way smarter than I am and so it can be hard to get my head around everything that they've done.

Eric Lippert
#2 is really saying something coming from you :o
280Z28
Yeah, I have difficulty getting my head around what Eric posts, so where does that leave me?!
Benjol
Well, that's because I'm not a great writer. Making technical stuff read easily off the page is pretty hard.
Eric Lippert
@Eric, at the level of the subject matter that you write, it takes work on the part of the reader to take apart each concept and walk through it conceptually to gain understanding. I'm not sure there's much a writer can do about that, other than making sure your meaning is clear.
Robert Harvey
+5  A: 

This weekend I played around with this, and created a couple of POCs to get a feel. And I'm loving everything. Reactive extensions (Rx) is really cool, as it introduces lot of new possibilities.

Here is the essence and summary.

.NET Rx team (this is not an official name) found that any push sequence (events, callbacks) can be viewed as a pull sequence (as we normally do while accessing enumerables) as well – or they are Dual in nature. In short observer/observable pattern is the dual of enumeration pattern.

So what is cool about about this duality? Anything you do with Pull sequences (read declarative style coding) is applicable to push sequences as well. Here are few aspects. You can create Observables from existing events and then use them as first class citizens in .NET – i.e, you may create an observable from an event, and expose the same as a property.

As IObservable is the mathematical dual of IEnumerable, .NET Rx facilitates LINQ over push sequences like Events, much like LINQ over IEnumerables

It gives greater freedom to compose new events – you can create specific events out of general events.

.NET Rx introduces two interfaces, IObservable and IObserver that "provides an alternative to using input and output adapters as the producer and consumer of event sources and sinks" and this will soon become the de-facto for writing asynchronous code in a declarative manner.

The source code as part of the second article contains a drawing application in WFP, with a version of System.Reactive.dll that I rebased to target .NET Framework 3.5 using Reflexil - You should be able to open the same in VS 2008 to play with Winfors or WPF

Check out this set of articles where I've posted my thoughts

amazedsaint
+3  A: 

The Reactive Extensions for .NET (Rx) is now available on DevLabs, with downloads for .NET 3.5, .NET 4, and Silverlight 3.

I'm really looking forward to seeing a variety of examples as opposed to the very few that have been shown so far. I'll be keeping an eye on the Rx Team Blog for info as it become available.

280Z28