Maintaining the Erlang View of the World

The Erlang view of the world is that everything is a process and that processes can interact only by exchanging messages. Having such a view of the world imposes conceptual integrity on our designs, making them easier to understand.

Imagine we want to write a web server in Erlang. A user requests a page called hello.html from our web server. The simplest possible web server looks like this:

 
web_server(Client) ->
 
receive
 
{Client, {get, Page}} ->
 
case​ file:read(Page) ​of
 
{ok, Bin} ->
 
Client ! {self(), {data, Bin}};
 
{error, _} ->
 
Client ! {self(), error}
 
end​,
 
web_server(Client)
 
end​.

But this code is simple only because all it does is receive and send Erlang terms. But clients ...

Get Programming Erlang, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.