Microsoft's New .NET Rx Framework Tackles Challenges of Asynchronous Programming
- By John K. Waters
Microsoft has quietly released the first key components of its .NET Reactive Framework (Rx), which allows developers to write LINQ (Language Integrated Query) expressions against events. Components of the Rx framework were included in the latest drop of the Silverlight Toolkit last month. A complete version is expected to be part of Visual Studio 2010 and will be supported by the .NET Framework 4.
The Rx Framework consists of a pair of interfaces (IObserver/IObservable), which 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, according to Erik Meijer, the well-known language designer who runs the Data Programmability Languages Team at Microsoft. Meijer outlined .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, such as you see in AJAX applications.
Meijer and software design engineer Wes Dyer have designed what Meijer describes 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."
A bold statement it may be, but 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," said Julie Lerman a .NET mentor and the author of the recently released book Programming Entity Framework (O'Reilly Media, Inc.) "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 New York-based custom technology solutions provider twentysix New York sees the Rx Framework as a solution to 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 said.
"Asynchronous programming is really hard." Lerman said. "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 the Presentation Platform Controls team at Microsoft has posted on his blog bits of sample code 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 have this very powerful mechanism to glue these things together," Meijer said. "Really, I've just sort of rephrased stuff that people have been doing for a long time." He points to the UNIX shell as an example. "UNIX pipelines is also an observable collection," he says, "because each stage of the pipeline pushes the value to the next stage. 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.
The Dutch computer scientist has been involved in the development of a wide range of languages, including Haskell, Mondrian, X#, Cω, C#, and even Visual Basic. His work these days aims to remove the impedance mismatch between databases and programming languages in a cloud context. That work led him to develop LINQ, a ground-breaking .NET Framework component that adds native data querying capabilities to .NET languages (C#, VB, etc.).
The most important thing for developers need to know about Meijer's latest creation is that the .NET Reactive Framework is likely to require some time to understand, Lerman said.
"Be patient while you wrap your head around this thing," she said. "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 a freelance journalist and author based in Palo Alto, CA.