MSDN Magazine - October 2008 - (Page 119) Easy async Build Concurrent Apps From Simple F# Expressions chance coble asynchronous programming is considered so difficult by many programmers that they create synchronous version of pro grams that could run more efficiently as asynchronous applications just to avoid the assumed complexity of asynchronous code. Until recently those choices had little consequence. However, with new opportunities in distributed computing such as multi core processors and serviceoriented architectures, developers are beginning to feel the burden. A classic example of this is in I/O operations, where processor time could be employed more prof itably while an I/Obound operation is taking place. Plenty of ap plications exist where many files are read and processed or where a complex orchestration of Web services is called upon to retrieve data that is processed and then sent to another service. In reality, an asynchronous program is a simpler arrangement than a synchronous one. An asynchronous program purposefully says nothing about the sequence of the commands to be executed. It is a lazy specification and thus should be simpler to define. One stumbling block that developers encounter with asynchro nous programming is that they become so concerned with getting concurrency right that they forget the core simplicity of the pro gram. Locks, semaphores, and other concurrent computing tools tend to focus the program’s layout less around its core logic and more around the concurrent management of its resources. That is where you will see the value of asynchronous expres sions in F#. You can separate simple programs from the concur rent control flow and reveal the simplicity and readability of your core program. Additionally, one of the most powerful aspects of the F# language is its ability to create libraries that can be called seamlessly from any other language compliant with the Microsoft .NET Framework, allowing you to leverage the intuitive parallel ism provided by F# asynchronous expressions from within exist ing imperative C# or Visual Basic code. In this article, I will demonstrate the essence of asynchronous ex pressions in F#. I will provide implementation examples and even show you how to incorporate your own frameworks into simple asynchronous primitives. Using the techniques I cover here, you This article is based on prerelease versions of the Visual studio addin for F# and related technologies. all information herein is subject to change. This article discusses: • Traditional and functional notation • asynchronous expressions • Building and using primitives • Working with other .nET languages Technologies discussed: F# October 2008 119
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.