.NET Rx Framework: A Watershed Advance in Asynch Programming
This summer Microsoft quietly released the first key components of its .NET Reactive (Rx) Framework, which allows developers to write Language Integrated Query (LINQ) expressions against events. Components of the Rx Framework were included in the latest drop of the Silverlight Toolkit. A complete version is expected to be part of Visual Studio 2010 and will be supported by .NET Framework 4.
According to language designer Erik Meijer, the Rx Framework consists of a pair of interfaces (IObserver/IObservable) that represent "push-based" observable collections, along with a library of extension methods that implement Microsoft's LINQ Standard Query Operators and other stream-transformation functions. Meijer runs the Data Programmability Languages Team at Microsoft, and he outlined the .NET Rx Framework during a session at the recent O'Reilly Open Source Convention (OSCON) in San Jose, Calif. Observable collections capture the essence of the subject/observer design pattern, Meijer said, and are especially useful for dealing with event-based and asynchronous programming.
Meijer and software design engineer Wes Dyer have designed what Meijer described as a major breakthrough in asynchronous programming: "Of all the work I've done in my career so far, this is the most exciting," Meijer told session attendees. "I know it's a bold statement, but I really believe that the problem of asynchronous programming events has been solved."
Veteran .NET developers agree that the Rx Framework is likely to change the way developers deal with asynchronous programming. "This is a completely new way of perceiving event handlers, delegates and asynchronous programming," says Julie Lerman, a .NET mentor and the author of the recently released book "Programming Entity Framework" (O'Reilly Media Inc., 2009). "I'm reacting like most programmers. We're uttering a collective, 'Oh my god.' They just peeled something open and showed us something new that has always been there."
Andrew Brust, chief of new technology at twentysix New York, says the Rx Framework solves the challenges inherent in asynchronous programming, which is the model employed in AJAX, Silverlight, Microsoft's Azure, cloud-based services and multi-core/multi-processor/multi-threaded programming. "It's an important step in making the delicate parts of AJAX, rich Internet applications, and cloud computing less disruptive to line-of-business programmers," Brust says.
"Asynchronous programming is really hard," Lerman notes. "It's hard for programmers to get their heads around it. Microsoft has been trying to find a way to make it more accessible to developers. In the same way that LINQ has made interacting with data objects easier, the Reactive Framework is going to make interacting with events easier. But not only that, it's going to give us a new level of access to working with events."
Microsoft included components of the Rx Framework in the latest version of its Silverlight Toolkit. The biggest chunk is a new assembly called system.reactive.dll, located in the bin folder of the Silverlight Toolkit Unit Tests. Jafar Husain, a software developer who works on Microsoft's Presentation Platform Controls team, has posted bits of sample code on his blog that can be downloaded and run inside Visual Studio 2008 via the Silverlight SDK.
"Just by thinking about events and asynchronous complications as collections, I know I have this very powerful mechanism to glue these things together," Meijer said at OSCON. "Really, I've just sort of rephrased stuff that people have been doing for a long time."
He pointed to the Unix shell as an example. "Unix pipelines are also an observable collection, because each stage of the pipeline pushes the value to the next stage," he said. "The way you glue these things together is by wiring up these data-flow networks." Another example: event-driven state machines in Windows Workflow, which is also a concrete type that implements the Observable interface.
Meijer has been involved in the development of a wide range of languages, including Haskell, Mondrian, X#, Cw, C# and even Visual Basic. He also led development of LINQ, which adds native data-querying capabilities to .NET languages such as C# and VB.
As for .NET Rx Framework, Lerman says it will take some time to understand. "Be patient while you wrap your head around this thing," she suggests. "Once it clicks, it will make perfect sense, and it will change the way you think about event handlers and delegates."
John K. Waters is the editor in chief of a number of Converge360.com sites, with a focus on high-end development, AI and future tech. He's been writing about cutting-edge technologies and culture of Silicon Valley for more than two decades, and he's written more than a dozen books. He also co-scripted the documentary film Silicon Valley: A 100 Year Renaissance, which aired on PBS. He can be reached at [email protected].