Erlang: For an absolute beginner

Last night I spent 30 minutes having a play with a new (to me) programming language, Erlang.

Its a language that will stretch my brain a bit, teach me to think about programming in a different way, and I know some folks using it (Mostly Smarkets and IRCCloud) who’s brains I can pick in the pub.

These are my quick notes from an Erlang newbie, hopefully useful to someone else getting started who just wants to install it, write Hello World and go from there.

Installing Erlang on OS X

This is incredibly easy with Homebrew (a package manager for OS X). As simple as:

brew install erlang

I expect they’ll be some cases where I need more than that stock install, but it’s good enough to get started. I haven’t tried it on my server, but it looks like a simple apt-get should do the trick, rather than the ball-ache of compiling from source.

Writing ‘Hello World’

The Erlang FAQ has the simplest ex&le:

-module(hello).
-export([hello_world/0]).

hello_world() -> io:fwrite("hello, world\n").

Save that as hello.erl (the name of the file needs to match the module name), run the Erlang shell (run erl) and compile it like so:

$ erl
1 > c(hello).

This will generate an Erlang byetcode file called hello.beam in your working directory. To run it, switch back to the Erlang shell and call the exported function on your module.

2 > hello:hello_world().
hello, world
ok
3 >

Simple. Thought i’d also recommend looking at a more complicated ‘Hello World’ that is a more idiomatic and Erlang-y version,

What next?

I asked on Twitter for some good Erlang resources, books, blogs, tutorials etc:

I guess my next step is to pick a small project to building in Erlang. It always seems better to have a simple project to help pick up a language.

At the moment I think i’m going to work through some of the Project Euler> problems and get to grips with the basics. Then perhaps build a toy web server, which has the added bonus of grokking more of the HTTP spec.

And finally…

It wouldn’t be a beginning Erlang blog post without the obligatory “Hello Joe” from the brilliant Erlang: The Movie

</embed>