views:

729

answers:

5

I understand the basics of Rx. Where I'm struggling is how you would actually use this beyond academic examples? What are some common, simple real-world scenarios where Rx is a much better solution than what we have today in .NET?

+7  A: 

For a bunch of good examples, see the 101 Rx Samples wiki

sblom
Thanks for the link. There's some pretty good samples there. Still don't quite see that head slapper - "oh that's the canonical problem this solves" sample. Then again, could just be me being slow on the uptake.
Keith Hill
A: 

Well, I've never heard of reactive programming. But I'm working on some chemical analysis software now that has a fairly long mathematical path from optical spectrum through background removal, interference removal, calibration curve calculation to the final concentration. (and a few other steps) Every step is represented in the GUI and every step can be performed in different ways. With conventional imperative programming it is difficult at best to correctly propagate all the changes that a user can make through to the final answer. I may have to look into this.

Thanks for the question.

Spike
+1  A: 
  • Device measurments
  • Data comming in over a message bus

In both cases now, the standard way to receive the data is via events, but if I want query syntax, or composition, then RX gives it to me where events don't.

Scott Weinstein
Good examples. Thanks.
Keith Hill
+2  A: 

First of all, IObservable is an event. So in anywhere you use events internally, you can use IObservable - and if you later need to apply LINQ to this event, you're able to do it without refactoring.

Second, RX is fit for any situation when you need to run your code asynchronousely. For example, calling a web service, or loading a large image.

But when it really starts to shine - if your program reaches some "critical mass" of IObservable usage and you start combining different observables you would be amazed how easy some tasks become.

Sergey Aldoukhov
A: 

Rx is very general so it has unlimited utility, just like IEnumerable/IEnumerator has unlimited utility. IE pulls values, IO pushes values.

Foreach is a concrete example of where IEnumerables come in handy, but that doesn't explain IEnumerable, or yield or anything. Same goes with Rx.

Being able to look at something from either a pull point of view, or a push point of view, and being able to control the direction or means, is very powerful, because now you can push and pull computations around at will, using LINQ query operators for "free", against an IO, because it's the mathematical dual of IE.

Richard Hein