Functional Programming with F#
F# is a succinct, high performance, type-inferred, functional language built on top of the .NET Framework. Microsoft has a solid base of imperative programming languages with VB.NET and C#, but there is a trend in computing that tends to be moving towards a more declarative style of programming. What's the difference? In an imperative language you write code that tells the compiler exactly how to do something, whereas in a declarative language you write code that says what you want to do, but leave the "how" part up to the compiler. Now, the ultimate declarative language would allow you to write something like "Morph the screen into something cool" and then compile your thoughts into a wicked screen saver or some such, but we're not there just yet. F# offers developers the opportunity to explore declarative concepts and offer a useful language to customers whose thinking is geared more towards functional development.
Another thought that probably comes to mind, is what does this mean for me? VB.NET and C# have already introduced some declarative concepts like LINQ. , In the years to come you're going to see more declarative features introduced into both languages. You may want to take a look at F# to familiarise yourself with declarative concepts so they're easier to absorb when they suddenly show up in the languages you use. For a deeper look at F#, check out the following resources:
- Microsoft F# Developers Center
- F# Hompage (Microsoft Research)
- An Introduction to Microsoft F# (PDC Video)
Processor speeds have started to level off, which means we can no longer rely on the latest and greatest chip to give our code a performance boost. Chipmakers have, however, continued the trend of putting more and more transistors on their chips, so the number of processors they can pack on a chip will continue to rise for the foreseeable future. But having all of the processors in the world is useless unless you have a way to take advantage of them all. To do that, developers need a way to incorporate parallel computing concepts into their applications.
Here's an example to accentuate the point. Let's say you have two applications running on a single processor. Assuming they have the same priority, they should share the processor equally, so both applications end up with about 50 percent of the processor and run at half speed. Now let's say you add another processor which allows each application to run on its own dedicated processor. It should result in an instant performance gain because they can both run at 100 percent without interfering with one another. But what happens if you take it a step further and add two more processors beyond that? Would it increase performance yet again? Unfortunately, the answer is likely no. You'll just end up with two idle processors.
Parallel computing is about breaking down large tasks into smaller tasks that can be processed individually. When you break down a task in this way, you can divide up the work between whatever resources you have at your disposal. If you have one processor and sixteen tasks, then you run all sixteen tasks on the same processor. If you have sixteen processors, then you can run one task on each processor and get work done much more quickly. In this scenario, adding more processors really can speed up an application. Microsoft is committed to making parallel computing capabilities more accessible to .NET developers by offering a development model that offloads the complexities of high performance computing. Developers are then free to focus on solving business needs, knowing that their solutions are built on a framework that scales along with the hardware.
Microsoft is laying a great foundation for parallel computing with the Parallel Extensions to the .NET Framework, which are included in .NET 4.0. It introduces the concept of tasks, which uses an enhanced thread pool to achieve some extremely compelling performance benefits over threads. It also provides the Parallel class, which contains static methods that help parallelise for loops, for each loops, and can even execute individual method calls in parallel. And it even includes Parallel LINQ, or PLINQ, which introduces syntax for running LINQ queries in parallel.
For a more in depth look at Parallelism, you can always check out these links:
- Parallel Programming for Managed Developers with Visual Studio 2010
- How to Use the Static Parallel Class
- Running Queries on Multi-Core Processors
- Taking Parallelism Mainstream
Looking at the Future of .NET
People always like to know what the future holds because our expectation of the future is what guides our actions in the present. And right now, it looks like .NET is positioned to give developers a leg up in the development arena. Languages are getting easier to use, the DLR provides a mechanism for talking to just about any language out there, and the complexities of parallel computing are being reigned in. In all, the future is looking even better for .NET developers.
Damon Armstrong is a senior architect with Cogent Company in Dallas, Texas, and author of 'Pro ASP.NET 2.0 Website Programming'. He specializes in Microsoft technologies with a focus on Web application design using ASP.NET. When not staying up all night coding, he can be found playing disc golf, softball, working on something for Carrollton Young Life, or recovering from coding all night.