Learning Erlang..? Why...?
I spent last week at two events:
- A beginners Erlang course given by Richard Carlsson on Monday to Wednesday, and
- The Erlang eXchange conference (sic) for the rest of the week.
As the Erlang site states Erlang is a functional programming language with an emphasis on concurrency, distribution, robustness, "soft" real-time (where response times are required within milliseconds), hot code upgrades, incremental code loading and external interfaces to connect to the outside world.
Why am I, someone who writes C# code for an investment bank, interested in this? There are three reasons:
- Self improvement: I'm always trying to expand my horizons, learn new things and challenge my own habits and world view. Erlang is an exploration of a completely new style of programming – think of it as personal development for the software developer in me.
-
The next big thing™: What everyone is looking for… It seems to me that Erlang is where Ruby was four years or so ago (pre-Rails) – on the cusp of transforming from a niche language to something mainstream and "in demand". What is the reason for this transformation? From my newbie perspective I can see that:
- Because of the way the Erlang language is designed, source code is relatively short and easy to understand (compared to my experience of writing C-like programming languages) and is thus faster to write and easier to maintain (and therefore cheaper and more fun).
- The move to multi-core architectures to speed things up means concurrency is now a very big issue. Erlang has an excellent and easy to understand means of dealing with concurrency (based on the so-called "actor" model, isolation and message passing). This is in contrast to most other languages that use threading, locks and shared resources – a methodology that is harder to get right and a nightmare to debug (I know this from bitter experience). As Erlang gets this sort of thing right I want to exploit concurrency in the simplest and most effective way possible.
- You get a lot for "free". The OTP libraries and other modules that come with the Erlang language provide lots of re-usable functionality – meaning developers don't have to constantly write so-called "boiler-plate" code before implementing the functionality the software was actually designed to fulfill. As most languages have large and feature rich libraries associated with them this aspect of Erlang isn't a differentiator – rather evidence that it is a mature and actively maintained language.
- Buzz. There is a book, a movie and lots of articles, blogs and websites out on the net. Erlang is starting to get noticed and I think it only a matter of time until a "killer" application arrives (a la "Rails" on Ruby) to suck more developers into using it.
- Free Software / Open Source: My interest in programming started after I installed Redhat 5 on an old 486 PC my father-in-law gave me back in the day… My commercial experience is completely within the proprietary world of .NET. I'd like to get commercial experience using free software (not the oxymoron it might look).
The course I mentioned at the start was great fun and Richard is an excellent teacher and obviously an expert in the field. All of us went away enthused and wanting more. Luckily there was more… the Erlang eXchange.
This was a relatively small affair but I got to meet lots of interesting people and see some of the cool things that have been done with Erlang. Richard took some photos that can be found here and Podcasts can be found at the Erlang eXchange website.
So what happens next..?
As those of us on the beginners track soon realised, we need to keep learning and practice our newly acquired skills. As a result, I'm devouring Joe Armstrong's book whilst on the train into work and we've organised ourselves a site on Google and intend to set projects for each other to keep us motivated and on track.
My first challenge to the rest of the group is to create a simple IRC-bot server:
- Start a bot server with a particular name. For example: bot:start("Frank").
- Connect with a username to the bot and talk and be ignored (as if in a regular IRC chan).
- The bot only pays attention when any input starts with its name. E.g.: "Frank, blah blah blah blah"
- You teach the bot new things by saying "Frank, learn Erlang is a cool language about Erlang". The pattern being: botname, learn X about Y.
- The bot responds to questions of the form "Frank, tell me about Erlang" with "Nicholas, Erlang is a cool language". The pattern being: botname, tell username/me about Y. And the response being: Username, X.
- The bot returns a list of all it knows by responding to "Frank, what do you know?" with "Nicholas, I can tell you about Erlang." The pattern being: Username, I can tell you about [list of all X's].
- Asking "Frank, help." returns a summary such as this one.
Why do an IRC bot? I can think of several good reasons:
- It should be a good challenge to write the core functionality described above using the skills we already have.
- At its heart, an IRC bot is pattern matching – something Erlang is supposed to be good at so we'd better explore what works and what doesn't.
- We can build upon this core to help learn other aspects of the language:
- Using ETS/DETS/Mnesia for data storage. This is a common requirement in Erlang projects so we might as well try doing it in this project.
- Using OTP to create the server architecture for the bot.
- Network programming so we can connect to a real IRC server to play.
I'll keep you posted how I get on.