« 16,147 km | Main | The path from crew member to speaker »
Functional programming – an emerging trend
By Frank Thomsen | July 17, 2008
Functional programming languages (FPL) has been around for many years. They can be traced as far back as the late 1950’s with the advent of LISP, and even further back if you consider the theoretical work which precedes them, and today there are a plethora of FPL’s. Yet we do not encounter them very often in our daily work. Why is that?
There are a number of explanations but first and foremost it is because functional programming is a fundamentally different programming paradigm and is considered somewhat esoteric by the majority of developers.
But lately FPL’s have entered the minds of the mainstream developer. When previously FPL’s where the domain of computer scientists and people with some bizarre need to mentally hurt themselves with exotic programming languages (which has been the prevalent opinion on functional programming among most developers I have known), you now find that developers, as well as IT-companies, take functional programming seriously.
What has happened?
Functional programming languages have lived a quiet life so far, so what has happened in the past 20-30 years (I think the most important FPL’s appeared in the late 1970’s and early 1980’s, but who am I to judge)? Well, when writing code, or controlling the money to a development team, you have a few important aspects to consider:
- The quality of the code. You want to be able to write stable code with as few bugs as possible, and you also want it to perform as the specifications state.
- The readability of the code. Since code is not static, even after the final release of a product, you want to write code that is readable and thus maintainable.
- Programmer performance. A programmer is a very expensive resource, and you want to maximize his/hers performance.
Code written in a FPL is generally more concise and readable than code written in an imperative programming language. Furthermore it tends to be more readable since you write your algorithms more like you would write the equivalent formulaes on paper. This makes the code more maintainable and makes the programmer more productive. And the fewer lines of code you have to write the fewer bugs you introduce, again making programmers more productive.
And since FPL’s have no side effects, no shared state (this is not entirely true, but true enough for now) the risk of introducing bugs is greatly reduced.
As Robert Martin (“Uncle Bob”) subtly states, and is being quoted in a previous post: “Our industry is plagued by an epidemic of very bad code.” We need to rethink our tools and methods in order to counter this.
Why bother learning a new language?
So is learning a new language even worth the trouble? Some people oppose but they are missing the point. The point is that we should be more adaptive in selecting our tools. We should select the tools that are the best for solving the task at hand, not just the tool we have in our hand at the moment. If I want to mow the lawn I will use my gas powered lawn mower, not the kitchen scissor even though it is possible. Likewise I would probably use Ruby on Rails or PHP to write a web based application instead of C++, and I would select Erlang if I was to write an application with literally thousands of tasks running concurrently.
Two languages you should keep an eye on
Currently there are two languages which have enormous potential:
- Erlang – because it is designed with concurrency and distribution in mind. This becomes more and more important as the CPU’s get more and more cores, and we need to address the complexity and error prone nature of concurrency in imperative languages. The actor model for concurrent computation that lies at the core of Erlang is very powerful, simple and stable, and is being used even with imperative languages in high performance computing applications.
- F# – because it seamlessly integrates with the entire .NET framework. With .NET we have the possibility to use whatever language fits each particular part of an application; C# or VB for the GUI, and F# for the data processing part (to name a few examples). Being a native .NET language really has far reaching possibilities, and it works on both Microsoft and Mono .NET platforms.
So is it all just dandy?
No. This is not a mindless rambling about how functional programming is going to save the world. FPL’s have their drawbacks too. For example, none of them will be my first choice when I have to write some graphical user interface. And if I have to use some legacy system I will definitely consider what support for integration with other technologies and languages is available. Likewise I would rather use Haskell or F# instead of C# or C++ to write a syntactic/semantic analyzer.
The simple fact is that no language or technology is the best solution for everything, so you should consider using what is best instead of trying to solve the task using an – for the specific task – inadequate technology.
I would like to give you some real world working examples of the benefits as well as drawbacks with the languages instead of just talking, but this is not the place. Instead you can take a cursory look at the Haskell Applications and Libraries page, as well as my personal blog where I occasionally write about functional programming.
Current trends
As I scan the web and talk to people I see an emerging trend, namely that functional programming is becoming more and more mainstream. Languages like Erlang and F# are really moving forward, and the languages are changing with a fast growing community behind it. Another indicator is that functional programming is being put on the agenda of developer conferences like JAOO and QCon. For example, Shriram Krishnamurthi will be talking about Scheme on this years JAOO conference in Aarhus in September, and Don Syme will be talking about F# on QCon in San Fransisco in November. This is not terribly impressive from a functional programmers point of view, but rest assured that more will come.
All in all this is very exciting, and I for one cannot wait to see what the future has in store for us. So to quote one of my favourite fictional writers (Terry Pratchett): “These are indeed interesting times.”
Category: JAOO | Tags: Don Syme, Erlang, F#, Frank Thomsen, Functional programming, Haskell, Shiram Krishnamurthi | 7 Comments »

July 18th, 2008 at 9:20 pm
Great article, Frank. I currently am studying C# but hope to learn F# as well, since Microsoft Visual Studio will support F# as well. Functional programming is very pragmatic, and less demanding in the sense of having to conform to an entire programming “kingdom” like .NET, even though .NET is really great now. Like you said, no single language resolves all. We need to be able to adapt to different languages per their capabilities.
July 18th, 2008 at 9:34 pm
only F# and Erlang?
What about Scala?
July 19th, 2008 at 11:41 am
I am sorry if the article is somewhat biased towards Erlang and F#, but the reasons stated in the article are still valid in the sense that they address key problems _and_ have a rapidly growing community. The fact that Microsoft will make F# a fully supported language is also worth mentioning. I tried to write the article as general as possible since I know that there are other FPL’s that each have their virtues.
I am not familiar with the Scala programming language, except that it runs on the JVM, integrates with existing Java libraries and supports anonymous functions, higher-order functions, currying, pattern-matching and other important FPL features. That makes it somewhat equal to F#, but is the community as large, and is the support (from both developers and companies alike) as that of F#? I don’t know. But given the above mentioned “features” of Scala it should be worth considering as on of our tools, definitely.
The landscape of programming is rapidly changing these years, with numerous functional and dynamical languages emerging. Some will come out on top in the end (if one can speculate about such a concept), but most will stay in the shadows. It all depends on features, community, integration and how much the language will evolve (like C# which has evolved quite a bit… perhaps too much).
July 19th, 2008 at 11:33 pm
i like this blog :
http://www.codecommit.com/blog/category/scala
July 22nd, 2008 at 11:52 am
Is Erlang and F# and other functional languages useful in a professional setting?
July 23rd, 2008 at 9:05 pm
Of course Erlang and F#, as well as other FPL’s, are useful in a professional setting.
Erlang has been used by Ericsson for many years in their telecomm software, and other companies are using Erlang as well. Amongst those most prominent are:
* Amazon, who is writing their SimpleDB in Erlang
* IMDB (Internet Movie Database) is switching from Perl to Erlang
* Facebook has implemented their chat software in Erlang
F# is a relatively new FPL, but already software companies are adopting it. And Microsoft is making it part of the official .NET language stack soon. Besides, F# is “just” OCaml with bi-directional .NET interoperability and a performance profile comparable to that if C#.
Haskell is also used in several professional applications, and other FPL’s have their niches too.
August 13th, 2008 at 12:16 pm
[...] Functional programming – an emerging trend [...]