Friday, March 28, 2008

Hello World in another language

The SPA 2008 Conference provided me with an opportunity to see the functional language Erlang for the first time. This isn't a new language (see panel session) having been in use for over 20 years in Ericson for applications such as PABX systems.

As with all programming languages, the Erlang version of 'Hello World!' was demonstrated but the more interesting examples were those which highlighted some of the features of Erlang that make it standout from the other languages. It is clearly particularly well suited to massively concurrent applications as it supports 'cheap' thread creation with data being shared by messages. A simple demonstration in calculating Fibonanci numbers showed. It also showed how crucial the implementation of a multi-threaded, parallel application is. Ensuring that the implementation was tail recursive created an application that returned a result in a few seconds; not doing this resulted in the result taking much longer.

With the move to multi-core architectures, efficient use of the cores through parallel applications becomes much more important. In the classic article, The Free Lunch is Over, Herb Sutter outlined that concurrency is the biggest change to impact software development since the adoption of OO. There is a fundamental change required in how programs are written, impacting good principles such as modularity, to ensure that the applications can take full advantage of the available processing resource. Erlang's approach has been to support parallel processing from the start and to make concurrency easy through the use of the Actor Model (contrast this with the approach taken by Haskell which uses Software Transactional Memory). Erlang's approach is extremely efficient and lightweight, and performs asynchronous processing; there is no guarantee on the ordering of messages.

Erlang clearly has a very different approach to any concurrent programming I have done in other languages such as C, C++, Ada, Java etc. In the short session I couldn't see many other benefits other than this but maybe this is just encouraging me to go away and experiment. I would be particularly interested in seeing how Erlang could be used in a mixed-language application, say Erlang , C++ and Java - I have already found an example which discussed the use of Erlang and Java.

Erlang also got me thinking. Many years ago, shortly after I graduated from university, one of my friends enrolled for a PhD in which he was to develop mathematical algorithms (specifically ordinary differential equations) to run efficiently in a multi-processor environment. His language was FORTRAN (there were other languages around at the time but FORTRAN was the dominant scientific language at the time) and he managed to get a number of the algorithms operating efficiently in multi-processor configurations. I wonder if Erlang had been around at the time, if it could have been used and would have made his job any easier?

No comments: