SlideShare a Scribd company logo
Erlang 
Elixir Webilea Hands-On Session 
at Obst & Gemüse, 19.3.2014 
By André Graf 
@der_graf / @erlio_basel
Preliminaries 
● Erlang and Elixir Programs are compiled for 
the BEAM* 
● Similar datatypes and runtime behavior 
● Different syntax, language features, stdlib 
*Bogdan/Björn's Erlang Abstract Machine
1986 
Erlang has been developed 
by Ericsson, for building 
highly available telco 
systems 
Massively concurrent 
server systems 
Server systems 
that run forever 
Hot-Code 
Upgrades 
Inherently parallel 
problem domain 
High availability 
through redundancy 
Debugging 
Live Systems
● Functional 
● Compiled 
● Dynamically typed 
● VM & Shell 
● Very lightweight processes 
● Processes don't share state 
● Message Passing Concurrency 
● Process Supervision (Let it crash) 
● Built-in Distribution 
● Hot-Code Upgrades
Erlang OTP 
● Architecture Patterns 
● Middlewares 
● Libraries 
● Tools 
● You could use Erlang witout OTP (nobody does) 
● OTP is included in the Erlang distribution 
● OTP is closely tied to the Erlang VM
1998 
Erlang has been 
opensourced and other 
companies started using it. 
Ericsson went for C++ 
Massively concurrent 
server systems 
Server systems 
that run forever 
Hot-Code 
Upgrades 
Inherently parallel 
problem domain 
High availability 
through redundancy 
Debugging 
Live Systems
2007
Introduction to Erlang/(Elixir) at a Webilea Hands-On Session
2012
● Functional 
● Compiled 
● Dynamically typed 
● VM & Shell 
● Very lightweight processes 
● Processes don't share state 
● Message Passing Concurrency 
● Process Supervision (Let it crash) 
● Built-in Distribution 
● Hot-Code Upgrades
Erlang vs. Elixir 
very subjective 
+ Elixir has a more familiar Syntax. 
+ Elixir fixes several language design mistakes 
from the past. * 
+ Elixir will bring more people to the Beam. 
+ Elixir has better meta-programming support. 
- Elixir has (currently) no own OTP framework. 
> killer for production use. 
* http://joearms.github.io/2013/05/31/a-week-with-elixir.html
Erlang Hands-On 
1. Installation Party 
2. Language introduction http://www.tryerlang.org/ 
3. My first Erlang module 
4. My first Erlang process 
5. Let it crash 
6. OTP behaviours gen_server / supervisor 
7. Recap / Discussion
Language Introduction 
Goto http://www.tryerlang.org/
My first Erlang Module 
● Module-Name == Filename.erl 
– e.g. my_first_module.erl 
-module(my_first_module). 
-export([my_first_function/1]). 
% this is a comment for my first function 
% this is another line of the comment 
my_first_function(Param) -> 
io:format(“wow my first function got called with param: ~p~n”, [Param]). 
1. Compile with erlc my_first_module.erl 
2. Start Erlang shell with: erl 
3. Call function my_first_module:my_first_function(“hello world”).
My first Erlang Process 
-module(my_first_module). 
-export([my_first_function/0, 
start_my_first_process/0]). 
my_first_function() -> 
receive 
Msg -> 
io:format(“wow my first process got a msg: ~p~n”, [Msg]) 
end. 
start_my_first_process() -> 
spawn(?MODULE, my_first_function, []). 
1. Compile with erlc my_first_module.erl 
or if you are inside the shell with: 
c(my_first_module). 
l(my_first_module). 
2. Start your first process: 
Pid = my_first_module:start_my_first_process(). 
3. Send your first message: 
Pid ! yeah_this_is_my_first_message. 
4. How can you reuse the Process???
Let it Crash 
-module(my_first_module). 
-export([my_first_function/0, 
start_my_first_process/0]). 
my_first_function() -> 
receive 
Msg -> 
dispatch_my_msg(Msg), 
my_first_function() %% yay, recursion! 
end. 
start_my_first_process() -> 
spawn(?MODULE, my_first_function, []). 
dispatch_my_msg({hello, world}) -> 
io:format(“what a great hello world~n”); 
dispatch_my_msg({A, B}) -> 
io:format(“tuple with ~p and ~p~n”, [A,B]). 
1. kinda stupid dispatcher, right???
Let it Crash 
-module(my_first_module). 
-export([my_first_function/0, 
start_my_first_monitored_process/1, 
my_monitor/1]). 
my_first_function() -> 
receive 
Msg -> 
dispatch_my_msg(Msg), 
my_first_function() 
end. 
my_monitor(ProcName) when is_atom(ProcName) -> 
Pid = spawn(?MODULE, my_first_function, []), 
true = register(ProcName, Pid), 
MonitorRef = monitor(process, Pid), 
receive 
{'DOWN', MonitorRef, _Type, Pid, _Info} -> 
my_monitor(ProcName); 
stop -> 
demonitor(MonitorRef) 
end. 
start_my_first_monitored_process(ProcName) -> 
spawn(?MODULE, my_monitor, [ProcName]). 
...
OTP Behaviours 
● gen_server 
– Generic way to write servers in Erlang OTP Style 
● Supervisor 
– A Supervisor that supervises other OTP compliant 
processes (e.g. gen_servers, gen_fsms)
gen_server 
-module(sample_gen_server). 
-behaviour(gen_server). 
-export([start_link/0]). 
%% gen_server callbacks 
-export([init/1, 
handle_call/3, 
handle_cast/2, 
handle_info/2, 
terminate/2, 
code_change/3]). 
%%% API 
start_link() -> 
gen_server:start_link(?MODULE, [], []). 
%%% gen_server callbacks 
init([]) -> 
{ok, []}. 
handle_call(_Request, _From, State) -> 
Reply = ok, 
{reply, Reply, State}. 
handle_cast(_Msg, State) -> 
{noreply, State}. 
handle_info(_Info, State) -> 
{noreply, State}. 
terminate(_Reason, _State) -> 
ok. 
code_change(_OldVsn, State, _Extra) -> 
{ok, State}.
supervisor -module(sample_supervisor). 
-behaviour(supervisor). 
-export([start_link/0]). 
%% Supervisor callbacks 
-export([init/1]). 
%% =================================================================== 
%% API functions 
%% =================================================================== 
start_link() -> 
supervisor:start_link({local, ?MODULE}, ?MODULE, []). 
%% =================================================================== 
%% Supervisor callbacks 
%% =================================================================== 
init([]) -> 
{ok, { {one_for_one, 5, 10}, [ %% 5 restarts within 10 seconds are allowed 
{sample_gen_server, { 
sample_gen_server, start_link, [] 
}, permanent, 5000, worker, [sample_gen_server]} 
]}}.
Recap/Discussion
Erlang 
Elixir Webilea Hands-On Session 
at Obst & Gemüse, 19.3.2014 
By André Graf 
@der_graf / @erlio_basel

More Related Content

PDF
VerneMQ @ Paris Erlang User Group June 29th 2015
PDF
Erlang and Elixir
PDF
Introduction to Elixir
PDF
The future of async i/o in Python
PDF
Elixir Into Production
PPTX
Python Programming Essentials - M25 - os and sys modules
PPTX
Async programming and python
PDF
A deep dive into PEP-3156 and the new asyncio module
VerneMQ @ Paris Erlang User Group June 29th 2015
Erlang and Elixir
Introduction to Elixir
The future of async i/o in Python
Elixir Into Production
Python Programming Essentials - M25 - os and sys modules
Async programming and python
A deep dive into PEP-3156 and the new asyncio module

What's hot (19)

PDF
Yurii Bodarev - OTP, Phoenix & Ecto: Three Pillars of Elixir
PDF
Python, do you even async?
PPTX
Introduction to Phoenix Framework (Elixir) 2016-01-07
PDF
Run rmi
PDF
Fluentd Hacking Guide at RubyKaigi 2014
PDF
Introduction to asyncio
PDF
maXbox Starter 42 Multiprocessing Programming
PDF
Tech Webinar: AUMENTARE LA SCALABILITÀ DELLE WEB APP CON SERVLET 3.1 ASYNC I/O
PDF
How do event loops work in Python?
PDF
Geeks Anonymes - Le langage Go
KEY
Ruby Concurrency and EventMachine
PPT
Erlang OTP
PDF
Bootstrap |> Elixir - Easy fun for busy developers
PDF
Get into Functional Programming with Clojure
PDF
Functional web with clojure
PDF
Speech for Windows Phone 8
PDF
Yaroslav Martsynyuk - Deploying Elixir/Phoenix with Distillery
PDF
Get Functional Programming with Clojure
ODP
Perl one-liners
Yurii Bodarev - OTP, Phoenix & Ecto: Three Pillars of Elixir
Python, do you even async?
Introduction to Phoenix Framework (Elixir) 2016-01-07
Run rmi
Fluentd Hacking Guide at RubyKaigi 2014
Introduction to asyncio
maXbox Starter 42 Multiprocessing Programming
Tech Webinar: AUMENTARE LA SCALABILITÀ DELLE WEB APP CON SERVLET 3.1 ASYNC I/O
How do event loops work in Python?
Geeks Anonymes - Le langage Go
Ruby Concurrency and EventMachine
Erlang OTP
Bootstrap |> Elixir - Easy fun for busy developers
Get into Functional Programming with Clojure
Functional web with clojure
Speech for Windows Phone 8
Yaroslav Martsynyuk - Deploying Elixir/Phoenix with Distillery
Get Functional Programming with Clojure
Perl one-liners
Ad

Similar to Introduction to Erlang/(Elixir) at a Webilea Hands-On Session (20)

PDF
Introduction To Erlang Final
PDF
Erlang, an overview
PDF
Beam me up, Scotty
PDF
Beam me up, scotty (PUG Roma)
PPTX
PDF
Erlang
PDF
Distributed Elixir
PDF
Golang workshop
PDF
Origins of Elixir programming language
PPTX
Java - A broad introduction
PPTX
The GO Language : From Beginners to Gophers
ODP
An introduction to erlang
PDF
Erlang Developments: The Good, The Bad and The Ugly
PDF
Concurrency, Robustness & Elixir SoCraTes 2015
PPT
Servlets and JavaServer Pages (JSP) from the B.Sc. Computer Science and Infor...
PDF
linux_internals_2.3 (1).pdf àaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
ODP
Elm & Elixir: Functional Programming and Web
PDF
Erlang in 10 minutes
KEY
Osdc 2011 michael_neale
Introduction To Erlang Final
Erlang, an overview
Beam me up, Scotty
Beam me up, scotty (PUG Roma)
Erlang
Distributed Elixir
Golang workshop
Origins of Elixir programming language
Java - A broad introduction
The GO Language : From Beginners to Gophers
An introduction to erlang
Erlang Developments: The Good, The Bad and The Ugly
Concurrency, Robustness & Elixir SoCraTes 2015
Servlets and JavaServer Pages (JSP) from the B.Sc. Computer Science and Infor...
linux_internals_2.3 (1).pdf àaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Elm & Elixir: Functional Programming and Web
Erlang in 10 minutes
Osdc 2011 michael_neale
Ad

Recently uploaded (20)

PPTX
Why Generative AI is the Future of Content, Code & Creativity?
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
Introduction to Artificial Intelligence
PDF
Digital Strategies for Manufacturing Companies
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
L1 - Introduction to python Backend.pptx
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
Reimagine Home Health with the Power of Agentic AI​
PPTX
Computer Software and OS of computer science of grade 11.pptx
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Softaken Excel to vCard Converter Software.pdf
Why Generative AI is the Future of Content, Code & Creativity?
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Introduction to Artificial Intelligence
Digital Strategies for Manufacturing Companies
How to Choose the Right IT Partner for Your Business in Malaysia
L1 - Introduction to python Backend.pptx
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Operating system designcfffgfgggggggvggggggggg
Odoo Companies in India – Driving Business Transformation.pdf
Reimagine Home Health with the Power of Agentic AI​
Computer Software and OS of computer science of grade 11.pptx
CHAPTER 2 - PM Management and IT Context
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
Understanding Forklifts - TECH EHS Solution
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Navsoft: AI-Powered Business Solutions & Custom Software Development
Softaken Excel to vCard Converter Software.pdf

Introduction to Erlang/(Elixir) at a Webilea Hands-On Session

  • 1. Erlang Elixir Webilea Hands-On Session at Obst & Gemüse, 19.3.2014 By André Graf @der_graf / @erlio_basel
  • 2. Preliminaries ● Erlang and Elixir Programs are compiled for the BEAM* ● Similar datatypes and runtime behavior ● Different syntax, language features, stdlib *Bogdan/Björn's Erlang Abstract Machine
  • 3. 1986 Erlang has been developed by Ericsson, for building highly available telco systems Massively concurrent server systems Server systems that run forever Hot-Code Upgrades Inherently parallel problem domain High availability through redundancy Debugging Live Systems
  • 4. ● Functional ● Compiled ● Dynamically typed ● VM & Shell ● Very lightweight processes ● Processes don't share state ● Message Passing Concurrency ● Process Supervision (Let it crash) ● Built-in Distribution ● Hot-Code Upgrades
  • 5. Erlang OTP ● Architecture Patterns ● Middlewares ● Libraries ● Tools ● You could use Erlang witout OTP (nobody does) ● OTP is included in the Erlang distribution ● OTP is closely tied to the Erlang VM
  • 6. 1998 Erlang has been opensourced and other companies started using it. Ericsson went for C++ Massively concurrent server systems Server systems that run forever Hot-Code Upgrades Inherently parallel problem domain High availability through redundancy Debugging Live Systems
  • 10. ● Functional ● Compiled ● Dynamically typed ● VM & Shell ● Very lightweight processes ● Processes don't share state ● Message Passing Concurrency ● Process Supervision (Let it crash) ● Built-in Distribution ● Hot-Code Upgrades
  • 11. Erlang vs. Elixir very subjective + Elixir has a more familiar Syntax. + Elixir fixes several language design mistakes from the past. * + Elixir will bring more people to the Beam. + Elixir has better meta-programming support. - Elixir has (currently) no own OTP framework. > killer for production use. * http://joearms.github.io/2013/05/31/a-week-with-elixir.html
  • 12. Erlang Hands-On 1. Installation Party 2. Language introduction http://www.tryerlang.org/ 3. My first Erlang module 4. My first Erlang process 5. Let it crash 6. OTP behaviours gen_server / supervisor 7. Recap / Discussion
  • 13. Language Introduction Goto http://www.tryerlang.org/
  • 14. My first Erlang Module ● Module-Name == Filename.erl – e.g. my_first_module.erl -module(my_first_module). -export([my_first_function/1]). % this is a comment for my first function % this is another line of the comment my_first_function(Param) -> io:format(“wow my first function got called with param: ~p~n”, [Param]). 1. Compile with erlc my_first_module.erl 2. Start Erlang shell with: erl 3. Call function my_first_module:my_first_function(“hello world”).
  • 15. My first Erlang Process -module(my_first_module). -export([my_first_function/0, start_my_first_process/0]). my_first_function() -> receive Msg -> io:format(“wow my first process got a msg: ~p~n”, [Msg]) end. start_my_first_process() -> spawn(?MODULE, my_first_function, []). 1. Compile with erlc my_first_module.erl or if you are inside the shell with: c(my_first_module). l(my_first_module). 2. Start your first process: Pid = my_first_module:start_my_first_process(). 3. Send your first message: Pid ! yeah_this_is_my_first_message. 4. How can you reuse the Process???
  • 16. Let it Crash -module(my_first_module). -export([my_first_function/0, start_my_first_process/0]). my_first_function() -> receive Msg -> dispatch_my_msg(Msg), my_first_function() %% yay, recursion! end. start_my_first_process() -> spawn(?MODULE, my_first_function, []). dispatch_my_msg({hello, world}) -> io:format(“what a great hello world~n”); dispatch_my_msg({A, B}) -> io:format(“tuple with ~p and ~p~n”, [A,B]). 1. kinda stupid dispatcher, right???
  • 17. Let it Crash -module(my_first_module). -export([my_first_function/0, start_my_first_monitored_process/1, my_monitor/1]). my_first_function() -> receive Msg -> dispatch_my_msg(Msg), my_first_function() end. my_monitor(ProcName) when is_atom(ProcName) -> Pid = spawn(?MODULE, my_first_function, []), true = register(ProcName, Pid), MonitorRef = monitor(process, Pid), receive {'DOWN', MonitorRef, _Type, Pid, _Info} -> my_monitor(ProcName); stop -> demonitor(MonitorRef) end. start_my_first_monitored_process(ProcName) -> spawn(?MODULE, my_monitor, [ProcName]). ...
  • 18. OTP Behaviours ● gen_server – Generic way to write servers in Erlang OTP Style ● Supervisor – A Supervisor that supervises other OTP compliant processes (e.g. gen_servers, gen_fsms)
  • 19. gen_server -module(sample_gen_server). -behaviour(gen_server). -export([start_link/0]). %% gen_server callbacks -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). %%% API start_link() -> gen_server:start_link(?MODULE, [], []). %%% gen_server callbacks init([]) -> {ok, []}. handle_call(_Request, _From, State) -> Reply = ok, {reply, Reply, State}. handle_cast(_Msg, State) -> {noreply, State}. handle_info(_Info, State) -> {noreply, State}. terminate(_Reason, _State) -> ok. code_change(_OldVsn, State, _Extra) -> {ok, State}.
  • 20. supervisor -module(sample_supervisor). -behaviour(supervisor). -export([start_link/0]). %% Supervisor callbacks -export([init/1]). %% =================================================================== %% API functions %% =================================================================== start_link() -> supervisor:start_link({local, ?MODULE}, ?MODULE, []). %% =================================================================== %% Supervisor callbacks %% =================================================================== init([]) -> {ok, { {one_for_one, 5, 10}, [ %% 5 restarts within 10 seconds are allowed {sample_gen_server, { sample_gen_server, start_link, [] }, permanent, 5000, worker, [sample_gen_server]} ]}}.
  • 22. Erlang Elixir Webilea Hands-On Session at Obst & Gemüse, 19.3.2014 By André Graf @der_graf / @erlio_basel