How is OTP distinct from the BEAM?

I am going to try to state my understanding of the distinction between OTP and the BEAM here below. Please comment if you think I got anything wrong, glossed over something important, or missed some aspect of either one.

Here goes…

The EAM in BEAM stands for “Erlang Abstract Machine”, so the BEAM is is just a virtual machine for executing erlang code, which compiles into BEAM-byte-code. So the BEAM is analogous to the JVM, if you’re familiar with the Java world: it is a virtual layer between the programming paradigm and the underlying hardware.

The BEAM is is an actual executable program that has to be installed on a physical machine and fired up. Once it is running, the BEAM is fed BEAM-byte-code, which is what Erlang and Elixir programs compile into, and the BEAM then translates this byte-code into machine-executable-code which the underlying hardware then executes.

OTP, on the other hand, is a set of behaviors, which are implemented in a library that has been installed on top of the BEAM. OTP is basically API contracts for writing software according to well-tested software architecture principles for working with a purely functional language in an environment in which processes are isolated and cheap and message passing is the only means of process communication – which is the architecture enforced by the BEAM.

So BEAM is the abstract machine which enforces a set of rules, and OTP is a set of principles for best executing code and writing software according to the rules enforced by the BEAM.

I guess my only question is: which one of these is more stable and how often do they change? I’ve noticed that asdf gives the following output in response to the command asdf list all elixir:

1.13.4
1.13.4-otp-22
1.13.4-otp-23
1.13.4-otp-24
1.13.4-otp-25
1.14.0-rc.0
1.14.0-rc.0-otp-23
1.14.0-rc.0-otp-24
1.14.0-rc.0-otp-25

So I guess OTP is constantly being updated, perhaps in response to incremental updates made to the BEAM.

Also, I guess the actual BEAM executable code is packaged with erlang, which has to be installed as a dependency of elixir?

4 Likes

You got beam correct, OTP is like “standard library” for the beam.

2 Likes

I would say that the Erlang standard library is the standard library. OTP is an application framework that also is included in the Erlang distribution, and you could choose not to use it if you like.

Although perhaps unhelpfully OTP seems to also the name of the distribution, or at least it is the name of the code repository.

3 Likes

This thread is worth a read re OTP :023:

3 Likes

Yeah things I would call OTP (like gen_server) are explicitly under the heading STDLIB in the Erlang docs. Otoh, something like tftp, xmerl… I think that’s in otp? But I would not want to call that STDLIB… (Though I guess python stdlib has lots of weird batteries included), there’s some cringey otp that probably should be considered stdlib (httpc) and some stuff that definitely should (crypto), even though both do not fall explicitly in the STDLIB heading

1 Like

BEAM is the runtime for Erlang, like the JVM is a runtime for for Java, and like CLR is for C#.

OTP is a library written in Erlang. When ran, it runs inside the BEAM, like all other Erlang code.

3 Likes