Erlang as an Embedded Application Platform

Recently, the programming language Erlang has found new fans owing to its success in helping a number of companies, most famously WhatsApp, build scalable web services. What has received less attention is its potential as a platform on which to build embedded applications.

What is Erlang?

Erlang originated within Ericsson as a language for creating telecoms switch software, suitable for handling a large number of simultaneous connections reliably. Originally proprietary, it is now available under an open source license.
Erlang code runs on its own virtual machine, which can in turn be run on most devices that are capable of running Linux. As noted previously, this now includes many embedded devices. The Erlang virtual machine provides a layer of abstraction between the application code and the underlying operating system which is often useful given the variable quality of Linux distributions available for particular hardware platforms.
Erlang is based on functional programming principles (avoids local state changes and mutable data), and its concurrency model is based around lightweight processes communicating by sending messages rather than sharing data. Elimination of the potential side effects of shared data allows for process isolation, making it easier to manage a large number of concurrent activities.

Why not just use C?

Embedded devices are becoming interconnected as part of the move towards the “internet of things”. Erlang’s background as a telecoms language makes it very suitable for creating such software. Writing networked applications in C generally requires direct use of operating system primitives, forcing the programmer to handle often difficult concurrency and multi-threading issues. As embedded systems become ever more complex, these problems can only get worse. Erlang, in contrast, isolates the programmer from much of the hard work. When required, such as for low-level driver manipulation or for efficient implementation of number crunching routines, there are a number of options for integrating C code with Erlang. Most practical Erlang systems are likely to include code written in both languages, with Erlang to implement higher level application logic and communications protocols, and C to handle lower level tasks.
The functional programming philosophy takes a little time to get used to, particularly for many embedded programmers who are often drawn from an electronics rather than computer science background. However, once a reasonable level of proficiency has been attained, significant productivity gains can be achieved. Separate studies performed at Ericsson and and Motorola suggest that it takes about one third of the number of lines of Erlang code compared to C++ to perform the same tasks, with a similar reduction in development time. With pressure on embedded teams to deliver more complex systems more quickly, this seems an advantage that should not be ignored.