My being a long-time C# coder, I finally decided to take a break from imperative programming and try something new. To be honest, I’ve quite often reached the point with my projects where I wonder: Couldn’t this be written so much more concisely and elegantly in another way? This thought occurs especially frequently in the context of mathematical and scientific coding. In response to this question, there have been suggestions (on more than one occasion) by David to try F# (specifically this functional language as he knew he couldn’t get me totally away from .NET yet). In case you’re not aware of it, it’s Microsft’s attempt at bringing functional programming to .NET, and has proven very successful so far.
It turned out that F# was surprisingly straightforward to learn, even for a language still in the beta stage (albeit the end thereof). Three or four days of regular coding gave me a pretty good idea of how it can be used for all sorts of purposes. Most likely my familiarity with lambda functions and LINQ in .NET 3.5/C# 3.0 made the task a lot easier. Even so, Microsoft have put together a number of helpful resources/links for getting started. The online documentation is especially useful given the (current) lack of XML intellisense comments inside Visual Studio. The Microsoft Research F# page and the F# Developer Center should be your first stops when learning the language. In addition, there is a pretty active community at hubFS and a host of blogs dedicated to F# out there. It seems like only a matter of time before there’s a multitude of forums and an IRC channel. I get the feeling that due to the ability to use the .NET framework from a functional language (and the fact that Microsoft will soon be making it a first-class language alongside C# and VB.NET), F# could have unprecented popularity.
After reading a few of the guides and beginner tutorials, I came across Project Euler, a series of mathematical/programming challenges that are particularly suited to the functional programming style. This website was really all I needed to get a solid grasp of the language, and was pretty fun aside from that. After trying some of the problems I finally had to admit that functional languages have their place in the programming world alongside imperative ones such as C# and C++. If you’re interested in some of my solutions to the first 23 problems, you can download the zipped project here. (Most solutions are under 5 lines in length, not including helper functions or input data.) I’ve had fair success optimising most of the algorithms, though in one or two cases you’ll find clearly more efficient solutions elsewhere. However, they’re not all terribly well commented, so feel free to question me about any of the algorithms.
Unfortunately I have quickly been forced back into the realm of imperative languages due to my project commitments (posts to come soon). Do however expect some upcoming posts and projects to feature F#, or at the least functional techniques.
As per the .Net base I can say there is a great chance of F# to click in the market. Found a nice updation on the recent technology from your blog.
thanks for that……..
[...] of the other talks given at the conference during the week. (The ones on the new F# language [see this post] and the future of C# looked reasonably interesting, but as contestants we were coding and testing [...]