Erlang talk at London HackspacePublished on 08 October 2009
Last night I gave an "Intro to Erlang" talk at a London Hackspace meetup. I did a quick audience survey first: About 75% did "web programming" (ruby,python,php,etc). Around 30% admitted to regularly using C/C++/Java or desktop/mobile app development. Less than 10% had much experience with functional programming.
I wanted to impress upon the audience that Erlang is a practical language, built by Ericsson with a specific purpose in mind. You use Erlang to build useful, scalable and reliable distributed systems in the real world. This was worth pointing out because when many people hear "functional programming" they immediately think of eccentric bearded academics proving the validity of their Haskell code and comparing Monads.
I skipped through the basics of sequential programming in Erlang pretty quickly and tried to spend most of the time showing how you handle processes and send messages. I built a basic Erlang server process that kept a count of how many operations it had done, explaining how it passes state to itself on every loop. Hopefully this helped some people grok how you can build servers that keep a global state by using recursion. I also showed off hot code reloading. We added another feature to the server and upgraded it without stopping it.
You can download the code I used (see link at the end) if you want to try out the examples from last night yourself. The last code I showed was an example of doing the same thing using genserver, so hopefully if you followed along you'll have a good understanding of what genserver is and why it exists.
Hot code reloading exampleI can't write a post about Erlang without including some code, so here's the basic example I used showing how hot code reloading works:
And if you were following along you saw something like this:
At this point we added support for "triple" to the example and showed how the fully-qualified call to loop (using the modulename:fun() instead of fun() syntax) causes the newest version of the module to be used:
You can see from the stats at the end that the global state was kept - the server process staying running during the code upgrade.
The slides, example code and basic mochiweb comet project we saw last night can be downloaded here. I should warn you that unless you saw my talk and the various explanations and disclaimers that went along with the code, it's probably not a good place to start or learn from. Have a look at www.learnyousomeerlang.com or get one of the two excellent Erlang books.
London HackspaceIf you live in London you should know about this. Russ and Jonty (who I worked with at Last.fm for years) started London Hackspace: "We run a dedicated space for people to learn and build things in London." There are workshops at hackspace meetups on topics ranging from Arduino and electronics hacking, to iPhone development, to Erlang and beyond. Their unofficial slogan could be "Beer & Hacking" - it's a great place to meet people doing interesting things in London, and to learn new things.
PlaydarPlaydar is my pet project at the moment. I talked about this last night too. I wrote it in C++ using Boost, mainly as an excuse to do something serious in C++. I've since seen the error of my masochistic ways and in the last week I've tossed out the 10,000 lines of C++ and rewritten it in Erlang. I'm not quite finished, but once I have feature parity between the two codebases I'll write an article comparing the two. As you might expect, the Erlang codebase is far superior in almost every way.
Recent 10 Articles
- BigWig: A better Erlang webtool (spawnfest entry)
- Erlang rebar tutorial: generating releases and upgrades
- Erlang/OTP releases: rebar, release_handler, .appup, etc
- Rewriting Playdar: C++ to Erlang, massive savings
- Erlang talk at London Hackspace
- Anti-RDBMS: A list of distributed key-value stores
- How we use IRC at Last.fm
- Getting to know ejabberd and writing modules
- ssh hack: connect directly to machine via a firewall box
- A Million-user Comet Application with Mochiweb, Part 3
[ See all 18 articles ]