Intro to 'Intro to Erlang'

This article describes what you can expect in the keyfunda event Intro to Erlang.

About Erlang

Erlang is an open-source concurrent programming language that has come into the limelight in recent years for building reliable and scalable distributed systems. Erlang runs on its own virtual machine in which programs spawn lightweight 'processes' that communicate by message passing. Erlang is particularly well suited for systems that require soft-real-time behaviour, fault tolerance, and high availability.

Erlang was originally created by Joe Armstrong and others at Ericsson to write software for telecommunication systems. In 1998 Ericsson open-sourced Erlang, and since then it has grown in popularity as a concurrent programming language for distributed systems. For some reason Erlang has acquired a cult status, possibly because of its rumoured extensive use in high-frequency financial trading. Over the past several years Erlang has been used to build many large-scale distributed systems such as messaging, queueing, gaming, configuration management, and cluster databases. These systems are well known in industry and it may come as a surprise to learn that they are in fact built using Erlang - here's another famous example.

What is concurrency?

Refer to this famous talk by Rob Pike about concurrency and how it is different from parallelism. Briefly, concurrency refers to a way of writing software where independent pieces of code appear to be executing simultaneously. The emergence of concurrency-oriented programming as an industry theme began with the shift to multi-core processors. That is another whole topic by itself, and we won't have time to discuss it in this event (which is focused on Erlang). So, for background, we have written a separate keyfunda article Semiconductor Scaling and Concurrent Clouds that provides a detailed discussion of the technical forces that drove this shift.

Why this event?

There are several excellent books and online resources for learning Erlang. So, one obvious question in your mind may be: what do I get in this event that I can't find in books, or online? This is a good question. We'll try and answer it below.

Reason 1: Is Erlang right for me?

You might have heard of Erlang or read about it, and be merely interested in finding out what it's all about. You may have even taken a look at some Erlang code and found that it doesn't resemble anything you've written so far. In this sense Erlang can be a mind-bender.

To give you an example, variables are immutable in Erlang. Once a variable is bound to a value you cannot change that binding. In C or Java or Python, you may write (leaving out syntax like semi-colons):

X = 41
X = 42

Doing this in the Erlang shell gives us this (the 1> and 2> are shell prompts):

1> X = 41.
41
2> X = 42.
** exception error: no match of right hand side value 42

Erlang doesn't allow the rebinding of X. This may completely baffle you, what kind of weird language is this? Turns out that immutable variables are a key design element of Erlang, it's one of the features that enables all that concurrent, distributed stuff.

If you noticed the period "." at the end of the Erlang shell expressions, that's not a typo, it's a secret Erlang incantation.

At the end of all this, you may decide that Erlang just doesn't suit you personally. Or maybe now is not the right time to get deeper into Erlang. Be that as it may, an introduction to Erlang is bound to expand your perspective as a software designer. Perhaps you will use some Erlang-inspired code in your current project. Or, you may prefer to use another concurrency-oriented language like Go, which has a philosophy of "share memory by communicating" (note: Rob Pike, whom we quoted earlier on the definition of concurrency, is one of the creators of Go).

That's why we've kept this event affordable. We don't claim to be the world's leading experts on Erlang (far from it), so we really don't have the moral imperative to charge a premium. However, we do plan on conducting a premium follow-up event on Erlang for which we will bring in one or two internationally renowned experts. It's obvious that the follow-up event will go deep into Erlang, it's meant for the serious programmer.

So, that's one reason.

Reason 2: Community

One of the questions we get asked often is how come the software scene is so vibrant in San Francisco? All the cool companies seem to get started there, jobs are plentiful, and everyone's zipping around in rideshare taxis to attend software meet-up's. What makes the place tick?

There is a famous essay by Paul Graham titled How to be Silicon Valley, in which he says: "If you could get the right ten thousand people to move from Silicon Valley to Buffalo, Buffalo would become Silicon Valley.... you only need two kinds of people to create a technology hub: rich people and nerds."

We need more nerds... er, people, to meet each other, talk, see what others are doing. So that's another hope with this event - that you will get a chance to see what the community is like in your city.

Reason 3: Elixir

Elixir is a new language being developed on top of the Erlang virtual machine. There is a growing groundswell of interest in Elixir, especially from programmers using other languages who feel a bit lost amidst Erlang's quirky syntax. Besides a more friendly syntax, Elixir offers attractive language features such as macros and enums, as explained nicely in this article. OTOH there is a traditionalist view that Elixir is an excuse for postponing the eventual learning of Erlang. Whichever camp you prefer, it is useful to have some idea about Elixir.

It's not possible to learn both Erlang and Elixir in one day (even one of them is difficult enough), and that is not our objective in this event. We'll give you a quick overview of Elixir, but we won't have time to write Elixir code.

Note, however, that we will be writing Erlang code.

Event outline

[Note: We may make some modifications to this outline, so do check back as we near the event date.]

This outline is based on what we think cannot be covered in one day i.e; this is a lot to cover. But then, if we didn't have challening content we would not be doing justice to the three reasons given above. So, fasten your seat belts and get ready for the ride!

  1. Installing Erlang (offline)
  2. Executive summary of Erlang and applications
  3. Basics
    • Shell and expressions
    • Modules, forms, funs
    • Tuples and Lists, Recursion
    • Code: Simple prime sieve
  4. Processes and messages
  5. Distributed Erlang
  6. Data storage: ETS and Mnesia
  7. A simpler server in Erlang
  8. A roadmap for learning OTP (see note below)
  9. A sip of Elixir
  10. Homework: Modeling an epidemic with Erlang

Note: OTP is really at the heart of using Erlang, it's a set of formalized design patterns to compose services, create supervised processes, handle failures, and perform hot code loading. OTP is a fairly complex topic, learning it takes a bit of experience with Erlang. In this event we will only give you a roadmap for learning OTP.

That's it. We hope we have provided you with a clear idea of what you can expect from this event, we welcome your comments below. If you have any specific questions do write to us at funda@keyfunda.com

See you at the event!