SlideShare a Scribd company logo
An Introduction to Erlang
      for Python programmers




   Paul Barry – Institute of Technology, Carlow in Ireland

            PyCon Ireland 2011 - October 2011
Grab the slides:

http://paulbarry.itcarlow.ie/ErlangWebcast.pdf




                                                 2
Disclaimer




             3
What exactly is Erlang?




                          4
“Erlang is a declarative,dynamically-typed,
  functional, concurrent, distributed and
   fault-tolerant programming language
     with garbage collection and code
    hot-swapping built into its runtime.”


                          Buzz-word city,
                              dude!




                                              5
Scratching an itch in
  the early '80s...




                        6
Why learn Erlang?




                    7
“Learn a new programming
   language every year”




                           8
“Buy at least one new
programming book every year”




                               9
So, really, why learn Erlang?




                                10
A better programmer,
    you will be...




                       11
Learn how others solve problems with a
different language, then apply these new
   techniques to your current language




                                           12
Learn what each language is good at,
  then pick the right tool for the job




                                         13
Works with a really big hammer!




                                  14
What is Erlang good at?




                          15
What Erlang Wasn't Designed To Do




                                    16
Erlang wasn't designed to...

    Run in a browser

    Process text efficiently

    Be easy to teach

    Be easy to learn

    Build dynamic websites

    Run on mobile phones

    Allow non-programmers to program

    Build GUIs
                                       17
Erlang was designed to build
software systems that never stop




                                   18
What exactly do you
 mean by “never”?




                      19
“Never” at Ericsson means “no more
                          than 4 minutes downtime per year”...




http://www.infoq.com/presentations/Systems-that-Never-Stop-Joe-Armstrong   20
Wow! That's 5 nines
   availability!*




                                21
             * 99.999% uptime
Let's build software
that's 100% defect free!




                           22
Let's throw lots and lots
of code at the problem and
      it'll go away, eh?




                              23
There has to be a better way




                               24
Let it crash!




Erlang programmers concentrate on
    coding for the correct case
      and crashing on failure




                                    25
Robustness is achieved by having
programmers concentrate on processes and the
   interactions (or messages) between them




                                           26
Early error detection/recovery and the use
 of concurrent programming techniques
  lets you build fault tolerant systems




                                             27
COP: Concurrency-Oriented Programming




                                        28
The problem is...




                    29
The problem is...




Erlang is a little weird




                           30
Consider this code...
-module(hello_server).

-export([hello/0]).



hello() ->

    receive

           {FromPID, Who} ->

              case Who of

                     robert -> FromPID ! "Hello Robert.";

                     mike -> FromPID ! "Hello Mike.";

                     joe -> FromPID ! "Hello Joe.";

                     _ -> FromPID ! "I don't know you."

              end,

              hello()

    end.

                                                            31
Strange punctuation symbols . ; ,
-module(hello_server).

-export([hello/0]).



hello() ->

    receive

           {FromPID, Who} ->

              case Who of

                     robert -> FromPID ! "Hello Robert.";

                     mike -> FromPID ! "Hello Mike.";

                     joe -> FromPID ! "Hello Joe.";

                     _ -> FromPID ! "I don't know you."

              end,

              hello()

    end.

                                                            32
Lots of arrows -> in lots of places
-module(hello_server).

-export([hello/0]).



hello() ->

    receive

           {FromPID, Who} ->

              case Who of

                     robert -> FromPID ! "Hello Robert.";

                     mike -> FromPID ! "Hello Mike.";

                     joe -> FromPID ! "Hello Joe.";

                     _ -> FromPID ! "I don't know you."

              end,

              hello()

    end.

                                                            33
Even stranger symbols - _ !
-module(hello_server).

-export([hello/0]).



hello() ->

    receive

           {FromPID, Who} ->

              case Who of

                     robert -> FromPID ! "Hello Robert.";

                     mike -> FromPID ! "Hello Mike.";

                     joe -> FromPID ! "Hello Joe.";

                     _ -> FromPID ! "I don't know you."

              end,

              hello()

    end.

                                                            34
What's the deal with [] {} and () ?
-module(hello_server).

-export([hello/0]).



hello() ->

    receive

           {FromPID, Who} ->

              case Who of

                     robert -> FromPID ! "Hello Robert.";

                     mike -> FromPID ! "Hello Mike.";

                     joe -> FromPID ! "Hello Joe.";

                     _ -> FromPID ! "I don't know you."

              end,

              hello()

    end.

                                                            35
Functions that call themselves
-module(hello_server).

-export([hello/0]).



hello() ->

    receive

           {FromPID, Who} ->

              case Who of

                     robert -> FromPID ! "Hello Robert.";

                     mike -> FromPID ! "Hello Mike.";

                     joe -> FromPID ! "Hello Joe.";

                     _ -> FromPID ! "I don't know you."

              end,

              hello()

    end.

                                                            36
This is weird...

and there's even more




                        37
Erlang Culture Shock




                       38
Shock #1

        Erlang's syntax is based on Prolog


-module(howdy).
-export([hi/1]).

hi(Name) ->
    io:format('Hi there, ~p!~n', [Name]).



{person, First, Last} = {person, 'Paul', 'Barry'}.

howdy:hi(Last).
                                                     39
Shock #2




Erlang is not object-oriented




                                40
Shock #3


Everything in Erlang is immutable


   Not just tuples and not just strings...

           EVERYTHING


                                             41
So... this doesn't work!


                    X = 10.
                  X = X + 1.


** exception error: no match of right hand side value 11


                  Y = X + 1.

                                                           42
Erlang's troublesome = operator




 The “=” operator does not mean “assign”

      It means “match” or “bind to”




                                           43
No side effects here!


     Destructive updates are forbidden

              and (as an added twist)

Variables must start with an Uppercase letter:


                       X
                     Pid
                     Func
                                                 44
Shock #4



There are no built-in looping constructs



        No for and no while



                                           45
So... how do you loop?




                         46
List Comprehensions

Erlang:
               Alist = [1, 2, 3, 4, 5].
               Doubled = [X*2 || X <- Alist].

Python:
               alist = [1, 2, 3, 4, 5]
               doubled = [x*2 for x in alist]


Note: alist and doubled are mutable; Alist and Doubled are not

                                                                 47
Shock #5




“Regular” looping is via recursion




                                     48
Spot the loop?
-module(hello_server).

-export([hello/0]).



hello() ->

    receive

           {FromPID, Who} ->

              case Who of

                  robert -> FromPID ! "Hello Robert.";

                  mike -> FromPID ! "Hello Mike.";

                  joe -> FromPID ! "Hello Joe.";

                  _ -> FromPID ! "I don't know you."

              end,

              hello()
                                                         49
    end.
Shock #6




Strings are stored as a
    list of integers




                          50
Sweet mother of all
things Erlang! Whose bright
       idea was that?




                              51
Shock #7


      There is no

if... then... else...

      statement



                        52
There are if and case expressions
     but... they're kinda weird




                                    53
54
With enough pig-headed persistence,
    weirdness can be overcome




                                      55
So... who do I call to
help me learn Erlang?




                          56
57
58
Erlang is a language you study
  as getting up-to-speed with
       Erlang takes time




                                 59
Web Resources

    http://www.erlang.org

    Try Erlang:
    
        http://www.tryerlang.org/

    “Learn Some Erlang For Great Good!”:
    
        http://learnyousomeerlang.com/

    The Erlang Factory:
    
        http://erlang-factory.com/

    InfoQ:
    
        http://www.infoq.com
                                           60
Some Unique “Characteristics”




                                61
Banned by Ericsson in 1998 for
   “not being open enough”




                                 62
63
http://video.google.com/videoplay?docid=-5830318882717959520
64
This is all great, but...
 how exactly do I use
   Erlang to build a
fault-tolerant system?




                            65
Learn Three Things


    Create an Erlang process with spawn()


    Send a message to a process with !


    Process a message with receive



                                            66
Remember this code?
%% Saved in 'hello_server.erl'.



-module(hello_server).

-export([hello/0]).



hello() ->

   receive

       {FromPID, Who} ->

             case Who of

                robert -> FromPID ! "Hello Robert.";

                mike -> FromPID ! "Hello Mike.";

                joe -> FromPID ! "Hello Joe.";

                _ -> FromPID ! "I don't know you."

             end,

             hello()

   end.                                                67
Create the hello() process




Pid = spawn(fun hello_server:hello/0).

<0.38.0>




                                    68
Send a message to a process with !


          Pid ! robert.

          robert




                                 69
A little twist




Pid ! {self(), robert}.

{<0.31.0>,robert}




                          70
Messages sent to a process with !
   are received by receive




                                    71
Can you spot the pattern match?
%% Saved in 'hello_server.erl'.



-module(hello_server).

-export([hello/0]).



hello() ->

   receive

          {FromPID, Who} ->

             case Who of

                 robert -> FromPID ! "Hello Robert.";

                 mike -> FromPID ! "Hello Mike.";

                 joe -> FromPID ! "Hello Joe.";

                 _ -> FromPID ! "I don't know you."

             end,

             hello()

   end.                                                 72
The {FromPID,                       Who}         tuple matches
%% Saved in 'hello_server.erl'.



-module(hello_server).

-export([hello/0]).



hello() ->

    receive

       {FromPID, Who} ->

              case Who of

                 robert -> FromPID ! "Hello Robert.";

                 mike -> FromPID ! "Hello Mike.";

                 joe -> FromPID ! "Hello Joe.";

                 _ -> FromPID ! "I don't know you."

              end,

              hello()

    end.                                                            73
Send a message back...
%% Saved in 'hello_server.erl'.



-module(hello_server).

-export([hello/0]).



hello() ->

    receive

       {FromPID, Who} ->

              case Who of

                 robert -> FromPID ! "Hello Robert.";

                 mike -> FromPID ! "Hello Mike.";

                 joe -> FromPID ! "Hello Joe.";

                 _ -> FromPID ! "I don't know you."

              end,

              hello()

    end.                                                74
spawn, send (!) then receive

Pid = spawn(fun hello_server:hello/0),
Pid ! {self(), robert},
receive
      Response ->
            Response
end.

"Hello Robert."


                                    75
Things get really interesting
       when the processes are
linked together with spawn_link()
     and the trap_exit signal




                                     76
Processes that are linked together can
react appropriately to EXIT messages from
  each other... and what happens next is
       controlled by the programmer




                                            77
Distributed Erlang

                    I need to spawn
                         hello/0                               hello/0 is
                      on glasnost...                          registered
pbmac.itcarlow.ie                                               as 'hr'




                                                                            78
                                       glasnost.itcarlow.ie
Pid = spawn(fun hello_server:hello/0),



                           becomes
Pid = spawn(‘hr@glasnost.itcarlow.ie’, hello_server, hello, []),




                                                                   79
Over time, you'll end up repeating
a lot of your process management code...




                                           80
81
OTP is the jewel in Erlang's crown




                                     82
So... if Erlang's so
cool, how come no one
       is using it?




                         83
The TIOBE Index




                  84
85
Erlang in Telecoms




                     86
Erlang in Data




                 87
Erlang on the Web




                    88
Erlang in Gaming

                                     “…Mochi Media is the world's
                                     largest browser-based games
                                     network, with more than 140 million
                                     monthly active users and 15,000
                                     games on nearly 40,000 publisher
                                     websites…”




                                                                           89
Check out Bob Ippolito’s Erlang-Factory talks!
More Erlang in Gaming




                                                                                              90
Thanks to Malcolm Dowse (of DemonWare, Dublin) for permission to use these
images, which were first delivered as part of Malcolm's talk to Erlang Factory London 2011.
So... is Erlang
worth learning?




                  91
Yes

      92
Lots more to discover...


         
             Fun with fun
    
      Bit-strings and bit syntax
          
            ETS and DETS
      
        “Live” code updating

  The Mnesia Distributed Database
      
        The Standard Library
               
                 CEAN


                                    93
Friendly Community



erlang-questions mailing list




                                94
Questions?




             95

More Related Content

Viewers also liked

Erlang - Because s**t Happens by Mahesh Paolini-Subramanya
Erlang - Because s**t Happens by Mahesh Paolini-SubramanyaErlang - Because s**t Happens by Mahesh Paolini-Subramanya
Erlang - Because s**t Happens by Mahesh Paolini-Subramanya
Hakka Labs
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)
Pavlo Baron
 
Clojure class
Clojure classClojure class
Clojure class
Aysylu Greenberg
 
VoltDB and Erlang - Tech planet 2012
VoltDB and Erlang - Tech planet 2012VoltDB and Erlang - Tech planet 2012
VoltDB and Erlang - Tech planet 2012
Eonblast
 
From Perl To Elixir
From Perl To ElixirFrom Perl To Elixir
From Perl To Elixir
Ruben Amortegui
 
Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)
Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)
Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)
Howard Lewis Ship
 
NDC London 2014: Erlang Patterns Matching Business Needs
NDC London 2014: Erlang Patterns Matching Business NeedsNDC London 2014: Erlang Patterns Matching Business Needs
NDC London 2014: Erlang Patterns Matching Business Needs
Torben Hoffmann
 
Elixir for aspiring Erlang developers
Elixir for aspiring Erlang developersElixir for aspiring Erlang developers
Elixir for aspiring Erlang developers
Torben Dohrn
 
Clojure Intro
Clojure IntroClojure Intro
Clojure Intro
thnetos
 
Elixir Into Production
Elixir Into ProductionElixir Into Production
Elixir Into Production
Jamie Winsor
 
Erlang - Because S**t Happens
Erlang - Because S**t HappensErlang - Because S**t Happens
Erlang - Because S**t Happens
Mahesh Paolini-Subramanya
 
Clojure: Towards The Essence of Programming
Clojure: Towards The Essence of ProgrammingClojure: Towards The Essence of Programming
Clojure: Towards The Essence of Programming
Howard Lewis Ship
 
Clojure, Plain and Simple
Clojure, Plain and SimpleClojure, Plain and Simple
Clojure, Plain and Simple
Ben Mabey
 
Clojure for Data Science
Clojure for Data ScienceClojure for Data Science
Clojure for Data Science
Mike Anderson
 
Clojure for Java developers
Clojure for Java developersClojure for Java developers
Clojure for Java developers
John Stevenson
 
Erlang - Concurrent Language for Concurrent World
Erlang - Concurrent Language for Concurrent WorldErlang - Concurrent Language for Concurrent World
Erlang - Concurrent Language for Concurrent World
Zvi Avraham
 
Functional programming in clojure
Functional programming in clojureFunctional programming in clojure
Functional programming in clojure
Juan-Manuel Gimeno
 
Basic Study for Erlang #2
Basic Study for Erlang #2Basic Study for Erlang #2
Basic Study for Erlang #2
Masahito Ikuta
 
Clojure: Towards The Essence Of Programming (What's Next? Conference, May 2011)
Clojure: Towards The Essence Of Programming (What's Next? Conference, May 2011)Clojure: Towards The Essence Of Programming (What's Next? Conference, May 2011)
Clojure: Towards The Essence Of Programming (What's Next? Conference, May 2011)
Howard Lewis Ship
 
Introduction to Erlang
Introduction to ErlangIntroduction to Erlang
Introduction to Erlang
Corrado Santoro
 

Viewers also liked (20)

Erlang - Because s**t Happens by Mahesh Paolini-Subramanya
Erlang - Because s**t Happens by Mahesh Paolini-SubramanyaErlang - Because s**t Happens by Mahesh Paolini-Subramanya
Erlang - Because s**t Happens by Mahesh Paolini-Subramanya
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)
 
Clojure class
Clojure classClojure class
Clojure class
 
VoltDB and Erlang - Tech planet 2012
VoltDB and Erlang - Tech planet 2012VoltDB and Erlang - Tech planet 2012
VoltDB and Erlang - Tech planet 2012
 
From Perl To Elixir
From Perl To ElixirFrom Perl To Elixir
From Perl To Elixir
 
Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)
Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)
Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)
 
NDC London 2014: Erlang Patterns Matching Business Needs
NDC London 2014: Erlang Patterns Matching Business NeedsNDC London 2014: Erlang Patterns Matching Business Needs
NDC London 2014: Erlang Patterns Matching Business Needs
 
Elixir for aspiring Erlang developers
Elixir for aspiring Erlang developersElixir for aspiring Erlang developers
Elixir for aspiring Erlang developers
 
Clojure Intro
Clojure IntroClojure Intro
Clojure Intro
 
Elixir Into Production
Elixir Into ProductionElixir Into Production
Elixir Into Production
 
Erlang - Because S**t Happens
Erlang - Because S**t HappensErlang - Because S**t Happens
Erlang - Because S**t Happens
 
Clojure: Towards The Essence of Programming
Clojure: Towards The Essence of ProgrammingClojure: Towards The Essence of Programming
Clojure: Towards The Essence of Programming
 
Clojure, Plain and Simple
Clojure, Plain and SimpleClojure, Plain and Simple
Clojure, Plain and Simple
 
Clojure for Data Science
Clojure for Data ScienceClojure for Data Science
Clojure for Data Science
 
Clojure for Java developers
Clojure for Java developersClojure for Java developers
Clojure for Java developers
 
Erlang - Concurrent Language for Concurrent World
Erlang - Concurrent Language for Concurrent WorldErlang - Concurrent Language for Concurrent World
Erlang - Concurrent Language for Concurrent World
 
Functional programming in clojure
Functional programming in clojureFunctional programming in clojure
Functional programming in clojure
 
Basic Study for Erlang #2
Basic Study for Erlang #2Basic Study for Erlang #2
Basic Study for Erlang #2
 
Clojure: Towards The Essence Of Programming (What's Next? Conference, May 2011)
Clojure: Towards The Essence Of Programming (What's Next? Conference, May 2011)Clojure: Towards The Essence Of Programming (What's Next? Conference, May 2011)
Clojure: Towards The Essence Of Programming (What's Next? Conference, May 2011)
 
Introduction to Erlang
Introduction to ErlangIntroduction to Erlang
Introduction to Erlang
 

Similar to Introduction to Erlang for Python Programmers

Confusing introduction to elixir
Confusing introduction to elixirConfusing introduction to elixir
Confusing introduction to elixir
Lauri Kainulainen
 
Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介
Wen-Tien Chang
 
Erlang is not a city in Germany
Erlang is not a city in GermanyErlang is not a city in Germany
Erlang is not a city in Germany
momo-13
 
Experiments in Sharing Java VM Technology with CRuby
Experiments in Sharing Java VM Technology with CRubyExperiments in Sharing Java VM Technology with CRuby
Experiments in Sharing Java VM Technology with CRuby
Matthew Gaudet
 
The hangover: A "modern" (?) high performance approach to build an offensive ...
The hangover: A "modern" (?) high performance approach to build an offensive ...The hangover: A "modern" (?) high performance approach to build an offensive ...
The hangover: A "modern" (?) high performance approach to build an offensive ...
Nelson Brito
 
Compiler
CompilerCompiler
Compiler
alekhya57
 
Origins of Elixir programming language
Origins of Elixir programming languageOrigins of Elixir programming language
Origins of Elixir programming language
Pivorak MeetUp
 
Rubinius - A Tool of the Future
Rubinius - A Tool of the FutureRubinius - A Tool of the Future
Rubinius - A Tool of the Future
evanphx
 
An intro to programming
An intro to programmingAn intro to programming
An intro to programming
WolfFlight
 
Erlang in 10 minutes
Erlang in 10 minutesErlang in 10 minutes
Erlang in 10 minutes
Maria Stylianou
 
Elixir
ElixirElixir
Sugar Presentation - YULHackers March 2009
Sugar Presentation - YULHackers March 2009Sugar Presentation - YULHackers March 2009
Sugar Presentation - YULHackers March 2009
spierre
 
TRICK2013 Results
TRICK2013 ResultsTRICK2013 Results
TRICK2013 Results
mametter
 
Golang #5: To Go or not to Go
Golang #5: To Go or not to GoGolang #5: To Go or not to Go
Golang #5: To Go or not to Go
Oliver N
 
The walking 0xDEAD
The walking 0xDEADThe walking 0xDEAD
The walking 0xDEAD
Carlos Garcia Prado
 
arduino
arduinoarduino
arduino
murbz
 
Elixir
ElixirElixir
Elixir
Robert Brown
 
[Ruxcon 2011] Post Memory Corruption Memory Analysis
[Ruxcon 2011] Post Memory Corruption Memory Analysis[Ruxcon 2011] Post Memory Corruption Memory Analysis
[Ruxcon 2011] Post Memory Corruption Memory Analysis
Moabi.com
 
An introduction to erlang
An introduction to erlangAn introduction to erlang
An introduction to erlang
Mirko Bonadei
 
[Kiwicon 2011] Post Memory Corruption Memory Analysis
[Kiwicon 2011] Post Memory Corruption Memory Analysis[Kiwicon 2011] Post Memory Corruption Memory Analysis
[Kiwicon 2011] Post Memory Corruption Memory Analysis
Moabi.com
 

Similar to Introduction to Erlang for Python Programmers (20)

Confusing introduction to elixir
Confusing introduction to elixirConfusing introduction to elixir
Confusing introduction to elixir
 
Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介
 
Erlang is not a city in Germany
Erlang is not a city in GermanyErlang is not a city in Germany
Erlang is not a city in Germany
 
Experiments in Sharing Java VM Technology with CRuby
Experiments in Sharing Java VM Technology with CRubyExperiments in Sharing Java VM Technology with CRuby
Experiments in Sharing Java VM Technology with CRuby
 
The hangover: A "modern" (?) high performance approach to build an offensive ...
The hangover: A "modern" (?) high performance approach to build an offensive ...The hangover: A "modern" (?) high performance approach to build an offensive ...
The hangover: A "modern" (?) high performance approach to build an offensive ...
 
Compiler
CompilerCompiler
Compiler
 
Origins of Elixir programming language
Origins of Elixir programming languageOrigins of Elixir programming language
Origins of Elixir programming language
 
Rubinius - A Tool of the Future
Rubinius - A Tool of the FutureRubinius - A Tool of the Future
Rubinius - A Tool of the Future
 
An intro to programming
An intro to programmingAn intro to programming
An intro to programming
 
Erlang in 10 minutes
Erlang in 10 minutesErlang in 10 minutes
Erlang in 10 minutes
 
Elixir
ElixirElixir
Elixir
 
Sugar Presentation - YULHackers March 2009
Sugar Presentation - YULHackers March 2009Sugar Presentation - YULHackers March 2009
Sugar Presentation - YULHackers March 2009
 
TRICK2013 Results
TRICK2013 ResultsTRICK2013 Results
TRICK2013 Results
 
Golang #5: To Go or not to Go
Golang #5: To Go or not to GoGolang #5: To Go or not to Go
Golang #5: To Go or not to Go
 
The walking 0xDEAD
The walking 0xDEADThe walking 0xDEAD
The walking 0xDEAD
 
arduino
arduinoarduino
arduino
 
Elixir
ElixirElixir
Elixir
 
[Ruxcon 2011] Post Memory Corruption Memory Analysis
[Ruxcon 2011] Post Memory Corruption Memory Analysis[Ruxcon 2011] Post Memory Corruption Memory Analysis
[Ruxcon 2011] Post Memory Corruption Memory Analysis
 
An introduction to erlang
An introduction to erlangAn introduction to erlang
An introduction to erlang
 
[Kiwicon 2011] Post Memory Corruption Memory Analysis
[Kiwicon 2011] Post Memory Corruption Memory Analysis[Kiwicon 2011] Post Memory Corruption Memory Analysis
[Kiwicon 2011] Post Memory Corruption Memory Analysis
 

More from Python Ireland

Async I/O in Python
Async I/O in PythonAsync I/O in Python
Async I/O in Python
Python Ireland
 
Python Ireland 2012 - Message brokers and Python by Fernando Ciciliati
Python Ireland 2012 - Message brokers and Python by Fernando Ciciliati Python Ireland 2012 - Message brokers and Python by Fernando Ciciliati
Python Ireland 2012 - Message brokers and Python by Fernando Ciciliati
Python Ireland
 
Python Ireland - Who, how, what
Python Ireland - Who, how, whatPython Ireland - Who, how, what
Python Ireland - Who, how, what
Python Ireland
 
Object Orientation vs. Functional Programming in Python
Object Orientation vs. Functional Programming in PythonObject Orientation vs. Functional Programming in Python
Object Orientation vs. Functional Programming in Python
Python Ireland
 
What's the Scoop with Python 3?
What's the Scoop with Python 3?What's the Scoop with Python 3?
What's the Scoop with Python 3?
Python Ireland
 
Google App Engine in 40 minutes (the absolute essentials)
Google App Engine in 40 minutes (the absolute essentials)Google App Engine in 40 minutes (the absolute essentials)
Google App Engine in 40 minutes (the absolute essentials)
Python Ireland
 
Web-service based Mobile Geospatial Application Development using Python
Web-service based Mobile Geospatial Application Development using PythonWeb-service based Mobile Geospatial Application Development using Python
Web-service based Mobile Geospatial Application Development using Python
Python Ireland
 
Utopia Kingdoms scaling case. From 4 users to 50.000+
Utopia Kingdoms scaling case. From 4 users to 50.000+Utopia Kingdoms scaling case. From 4 users to 50.000+
Utopia Kingdoms scaling case. From 4 users to 50.000+
Python Ireland
 
The Larch - a visual interactive programming environment
The Larch - a visual interactive programming environmentThe Larch - a visual interactive programming environment
The Larch - a visual interactive programming environment
Python Ireland
 
Python vs JLizard.... a python logging experience
Python vs JLizard.... a python logging experiencePython vs JLizard.... a python logging experience
Python vs JLizard.... a python logging experience
Python Ireland
 
Vim and Python
Vim and PythonVim and Python
Vim and Python
Python Ireland
 
Python Ireland Nov 2009 Talk - Appengine
Python Ireland Nov 2009 Talk - AppenginePython Ireland Nov 2009 Talk - Appengine
Python Ireland Nov 2009 Talk - Appengine
Python Ireland
 
Python Ireland May 2011 - What is Pyramid and where is it with respect to Dja...
Python Ireland May 2011 - What is Pyramid and where is it with respect to Dja...Python Ireland May 2011 - What is Pyramid and where is it with respect to Dja...
Python Ireland May 2011 - What is Pyramid and where is it with respect to Dja...
Python Ireland
 
Python Ireland Nov 2010 Talk: Unit Testing
Python Ireland Nov 2010 Talk: Unit TestingPython Ireland Nov 2010 Talk: Unit Testing
Python Ireland Nov 2010 Talk: Unit Testing
Python Ireland
 
Python Ireland Nov 2010 - RESTing with Django
Python Ireland Nov 2010 - RESTing with DjangoPython Ireland Nov 2010 - RESTing with Django
Python Ireland Nov 2010 - RESTing with Django
Python Ireland
 
Python Ireland Feb '11 Talks: Introduction to Python
Python Ireland Feb '11 Talks: Introduction to PythonPython Ireland Feb '11 Talks: Introduction to Python
Python Ireland Feb '11 Talks: Introduction to Python
Python Ireland
 
Python Ireland Dec Talks - Windows Azure -- The Nuts and Bolts
Python Ireland Dec Talks - Windows Azure -- The Nuts and BoltsPython Ireland Dec Talks - Windows Azure -- The Nuts and Bolts
Python Ireland Dec Talks - Windows Azure -- The Nuts and Bolts
Python Ireland
 
Lambada
LambadaLambada
Python for cloud computing
Python for cloud computingPython for cloud computing
Python for cloud computing
Python Ireland
 
IPython: The awesome python shell
IPython: The awesome python shellIPython: The awesome python shell
IPython: The awesome python shell
Python Ireland
 

More from Python Ireland (20)

Async I/O in Python
Async I/O in PythonAsync I/O in Python
Async I/O in Python
 
Python Ireland 2012 - Message brokers and Python by Fernando Ciciliati
Python Ireland 2012 - Message brokers and Python by Fernando Ciciliati Python Ireland 2012 - Message brokers and Python by Fernando Ciciliati
Python Ireland 2012 - Message brokers and Python by Fernando Ciciliati
 
Python Ireland - Who, how, what
Python Ireland - Who, how, whatPython Ireland - Who, how, what
Python Ireland - Who, how, what
 
Object Orientation vs. Functional Programming in Python
Object Orientation vs. Functional Programming in PythonObject Orientation vs. Functional Programming in Python
Object Orientation vs. Functional Programming in Python
 
What's the Scoop with Python 3?
What's the Scoop with Python 3?What's the Scoop with Python 3?
What's the Scoop with Python 3?
 
Google App Engine in 40 minutes (the absolute essentials)
Google App Engine in 40 minutes (the absolute essentials)Google App Engine in 40 minutes (the absolute essentials)
Google App Engine in 40 minutes (the absolute essentials)
 
Web-service based Mobile Geospatial Application Development using Python
Web-service based Mobile Geospatial Application Development using PythonWeb-service based Mobile Geospatial Application Development using Python
Web-service based Mobile Geospatial Application Development using Python
 
Utopia Kingdoms scaling case. From 4 users to 50.000+
Utopia Kingdoms scaling case. From 4 users to 50.000+Utopia Kingdoms scaling case. From 4 users to 50.000+
Utopia Kingdoms scaling case. From 4 users to 50.000+
 
The Larch - a visual interactive programming environment
The Larch - a visual interactive programming environmentThe Larch - a visual interactive programming environment
The Larch - a visual interactive programming environment
 
Python vs JLizard.... a python logging experience
Python vs JLizard.... a python logging experiencePython vs JLizard.... a python logging experience
Python vs JLizard.... a python logging experience
 
Vim and Python
Vim and PythonVim and Python
Vim and Python
 
Python Ireland Nov 2009 Talk - Appengine
Python Ireland Nov 2009 Talk - AppenginePython Ireland Nov 2009 Talk - Appengine
Python Ireland Nov 2009 Talk - Appengine
 
Python Ireland May 2011 - What is Pyramid and where is it with respect to Dja...
Python Ireland May 2011 - What is Pyramid and where is it with respect to Dja...Python Ireland May 2011 - What is Pyramid and where is it with respect to Dja...
Python Ireland May 2011 - What is Pyramid and where is it with respect to Dja...
 
Python Ireland Nov 2010 Talk: Unit Testing
Python Ireland Nov 2010 Talk: Unit TestingPython Ireland Nov 2010 Talk: Unit Testing
Python Ireland Nov 2010 Talk: Unit Testing
 
Python Ireland Nov 2010 - RESTing with Django
Python Ireland Nov 2010 - RESTing with DjangoPython Ireland Nov 2010 - RESTing with Django
Python Ireland Nov 2010 - RESTing with Django
 
Python Ireland Feb '11 Talks: Introduction to Python
Python Ireland Feb '11 Talks: Introduction to PythonPython Ireland Feb '11 Talks: Introduction to Python
Python Ireland Feb '11 Talks: Introduction to Python
 
Python Ireland Dec Talks - Windows Azure -- The Nuts and Bolts
Python Ireland Dec Talks - Windows Azure -- The Nuts and BoltsPython Ireland Dec Talks - Windows Azure -- The Nuts and Bolts
Python Ireland Dec Talks - Windows Azure -- The Nuts and Bolts
 
Lambada
LambadaLambada
Lambada
 
Python for cloud computing
Python for cloud computingPython for cloud computing
Python for cloud computing
 
IPython: The awesome python shell
IPython: The awesome python shellIPython: The awesome python shell
IPython: The awesome python shell
 

Recently uploaded

Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
Dinusha Kumarasiri
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
Shinana2
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
LucaBarbaro3
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Tatiana Kojar
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
Wouter Lemaire
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
Pravash Chandra Das
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
fredae14
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 

Recently uploaded (20)

Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 

Introduction to Erlang for Python Programmers

  • 1. An Introduction to Erlang for Python programmers Paul Barry – Institute of Technology, Carlow in Ireland PyCon Ireland 2011 - October 2011
  • 4. What exactly is Erlang? 4
  • 5. “Erlang is a declarative,dynamically-typed, functional, concurrent, distributed and fault-tolerant programming language with garbage collection and code hot-swapping built into its runtime.” Buzz-word city, dude! 5
  • 6. Scratching an itch in the early '80s... 6
  • 8. “Learn a new programming language every year” 8
  • 9. “Buy at least one new programming book every year” 9
  • 10. So, really, why learn Erlang? 10
  • 11. A better programmer, you will be... 11
  • 12. Learn how others solve problems with a different language, then apply these new techniques to your current language 12
  • 13. Learn what each language is good at, then pick the right tool for the job 13
  • 14. Works with a really big hammer! 14
  • 15. What is Erlang good at? 15
  • 16. What Erlang Wasn't Designed To Do 16
  • 17. Erlang wasn't designed to...  Run in a browser  Process text efficiently  Be easy to teach  Be easy to learn  Build dynamic websites  Run on mobile phones  Allow non-programmers to program  Build GUIs 17
  • 18. Erlang was designed to build software systems that never stop 18
  • 19. What exactly do you mean by “never”? 19
  • 20. “Never” at Ericsson means “no more than 4 minutes downtime per year”... http://www.infoq.com/presentations/Systems-that-Never-Stop-Joe-Armstrong 20
  • 21. Wow! That's 5 nines availability!* 21 * 99.999% uptime
  • 22. Let's build software that's 100% defect free! 22
  • 23. Let's throw lots and lots of code at the problem and it'll go away, eh? 23
  • 24. There has to be a better way 24
  • 25. Let it crash! Erlang programmers concentrate on coding for the correct case and crashing on failure 25
  • 26. Robustness is achieved by having programmers concentrate on processes and the interactions (or messages) between them 26
  • 27. Early error detection/recovery and the use of concurrent programming techniques lets you build fault tolerant systems 27
  • 30. The problem is... Erlang is a little weird 30
  • 31. Consider this code... -module(hello_server). -export([hello/0]). hello() -> receive {FromPID, Who} -> case Who of robert -> FromPID ! "Hello Robert."; mike -> FromPID ! "Hello Mike."; joe -> FromPID ! "Hello Joe."; _ -> FromPID ! "I don't know you." end, hello() end. 31
  • 32. Strange punctuation symbols . ; , -module(hello_server). -export([hello/0]). hello() -> receive {FromPID, Who} -> case Who of robert -> FromPID ! "Hello Robert."; mike -> FromPID ! "Hello Mike."; joe -> FromPID ! "Hello Joe."; _ -> FromPID ! "I don't know you." end, hello() end. 32
  • 33. Lots of arrows -> in lots of places -module(hello_server). -export([hello/0]). hello() -> receive {FromPID, Who} -> case Who of robert -> FromPID ! "Hello Robert."; mike -> FromPID ! "Hello Mike."; joe -> FromPID ! "Hello Joe."; _ -> FromPID ! "I don't know you." end, hello() end. 33
  • 34. Even stranger symbols - _ ! -module(hello_server). -export([hello/0]). hello() -> receive {FromPID, Who} -> case Who of robert -> FromPID ! "Hello Robert."; mike -> FromPID ! "Hello Mike."; joe -> FromPID ! "Hello Joe."; _ -> FromPID ! "I don't know you." end, hello() end. 34
  • 35. What's the deal with [] {} and () ? -module(hello_server). -export([hello/0]). hello() -> receive {FromPID, Who} -> case Who of robert -> FromPID ! "Hello Robert."; mike -> FromPID ! "Hello Mike."; joe -> FromPID ! "Hello Joe."; _ -> FromPID ! "I don't know you." end, hello() end. 35
  • 36. Functions that call themselves -module(hello_server). -export([hello/0]). hello() -> receive {FromPID, Who} -> case Who of robert -> FromPID ! "Hello Robert."; mike -> FromPID ! "Hello Mike."; joe -> FromPID ! "Hello Joe."; _ -> FromPID ! "I don't know you." end, hello() end. 36
  • 37. This is weird... and there's even more 37
  • 39. Shock #1 Erlang's syntax is based on Prolog -module(howdy). -export([hi/1]). hi(Name) -> io:format('Hi there, ~p!~n', [Name]). {person, First, Last} = {person, 'Paul', 'Barry'}. howdy:hi(Last). 39
  • 40. Shock #2 Erlang is not object-oriented 40
  • 41. Shock #3 Everything in Erlang is immutable Not just tuples and not just strings... EVERYTHING 41
  • 42. So... this doesn't work! X = 10. X = X + 1. ** exception error: no match of right hand side value 11 Y = X + 1. 42
  • 43. Erlang's troublesome = operator The “=” operator does not mean “assign” It means “match” or “bind to” 43
  • 44. No side effects here! Destructive updates are forbidden and (as an added twist) Variables must start with an Uppercase letter: X Pid Func 44
  • 45. Shock #4 There are no built-in looping constructs No for and no while 45
  • 46. So... how do you loop? 46
  • 47. List Comprehensions Erlang: Alist = [1, 2, 3, 4, 5]. Doubled = [X*2 || X <- Alist]. Python: alist = [1, 2, 3, 4, 5] doubled = [x*2 for x in alist] Note: alist and doubled are mutable; Alist and Doubled are not 47
  • 48. Shock #5 “Regular” looping is via recursion 48
  • 49. Spot the loop? -module(hello_server). -export([hello/0]). hello() -> receive {FromPID, Who} -> case Who of robert -> FromPID ! "Hello Robert."; mike -> FromPID ! "Hello Mike."; joe -> FromPID ! "Hello Joe."; _ -> FromPID ! "I don't know you." end, hello() 49 end.
  • 50. Shock #6 Strings are stored as a list of integers 50
  • 51. Sweet mother of all things Erlang! Whose bright idea was that? 51
  • 52. Shock #7 There is no if... then... else... statement 52
  • 53. There are if and case expressions but... they're kinda weird 53
  • 54. 54
  • 55. With enough pig-headed persistence, weirdness can be overcome 55
  • 56. So... who do I call to help me learn Erlang? 56
  • 57. 57
  • 58. 58
  • 59. Erlang is a language you study as getting up-to-speed with Erlang takes time 59
  • 60. Web Resources  http://www.erlang.org  Try Erlang:  http://www.tryerlang.org/  “Learn Some Erlang For Great Good!”:  http://learnyousomeerlang.com/  The Erlang Factory:  http://erlang-factory.com/  InfoQ:  http://www.infoq.com 60
  • 62. Banned by Ericsson in 1998 for “not being open enough” 62
  • 64. 64
  • 65. This is all great, but... how exactly do I use Erlang to build a fault-tolerant system? 65
  • 66. Learn Three Things  Create an Erlang process with spawn()  Send a message to a process with !  Process a message with receive 66
  • 67. Remember this code? %% Saved in 'hello_server.erl'. -module(hello_server). -export([hello/0]). hello() -> receive {FromPID, Who} -> case Who of robert -> FromPID ! "Hello Robert."; mike -> FromPID ! "Hello Mike."; joe -> FromPID ! "Hello Joe."; _ -> FromPID ! "I don't know you." end, hello() end. 67
  • 68. Create the hello() process Pid = spawn(fun hello_server:hello/0). <0.38.0> 68
  • 69. Send a message to a process with ! Pid ! robert. robert 69
  • 70. A little twist Pid ! {self(), robert}. {<0.31.0>,robert} 70
  • 71. Messages sent to a process with ! are received by receive 71
  • 72. Can you spot the pattern match? %% Saved in 'hello_server.erl'. -module(hello_server). -export([hello/0]). hello() -> receive {FromPID, Who} -> case Who of robert -> FromPID ! "Hello Robert."; mike -> FromPID ! "Hello Mike."; joe -> FromPID ! "Hello Joe."; _ -> FromPID ! "I don't know you." end, hello() end. 72
  • 73. The {FromPID, Who} tuple matches %% Saved in 'hello_server.erl'. -module(hello_server). -export([hello/0]). hello() -> receive {FromPID, Who} -> case Who of robert -> FromPID ! "Hello Robert."; mike -> FromPID ! "Hello Mike."; joe -> FromPID ! "Hello Joe."; _ -> FromPID ! "I don't know you." end, hello() end. 73
  • 74. Send a message back... %% Saved in 'hello_server.erl'. -module(hello_server). -export([hello/0]). hello() -> receive {FromPID, Who} -> case Who of robert -> FromPID ! "Hello Robert."; mike -> FromPID ! "Hello Mike."; joe -> FromPID ! "Hello Joe."; _ -> FromPID ! "I don't know you." end, hello() end. 74
  • 75. spawn, send (!) then receive Pid = spawn(fun hello_server:hello/0), Pid ! {self(), robert}, receive Response -> Response end. "Hello Robert." 75
  • 76. Things get really interesting when the processes are linked together with spawn_link() and the trap_exit signal 76
  • 77. Processes that are linked together can react appropriately to EXIT messages from each other... and what happens next is controlled by the programmer 77
  • 78. Distributed Erlang I need to spawn hello/0 hello/0 is on glasnost... registered pbmac.itcarlow.ie as 'hr' 78 glasnost.itcarlow.ie
  • 79. Pid = spawn(fun hello_server:hello/0), becomes Pid = spawn(‘hr@glasnost.itcarlow.ie’, hello_server, hello, []), 79
  • 80. Over time, you'll end up repeating a lot of your process management code... 80
  • 81. 81
  • 82. OTP is the jewel in Erlang's crown 82
  • 83. So... if Erlang's so cool, how come no one is using it? 83
  • 85. 85
  • 88. Erlang on the Web 88
  • 89. Erlang in Gaming “…Mochi Media is the world's largest browser-based games network, with more than 140 million monthly active users and 15,000 games on nearly 40,000 publisher websites…” 89 Check out Bob Ippolito’s Erlang-Factory talks!
  • 90. More Erlang in Gaming 90 Thanks to Malcolm Dowse (of DemonWare, Dublin) for permission to use these images, which were first delivered as part of Malcolm's talk to Erlang Factory London 2011.
  • 91. So... is Erlang worth learning? 91
  • 92. Yes 92
  • 93. Lots more to discover...  Fun with fun  Bit-strings and bit syntax  ETS and DETS  “Live” code updating  The Mnesia Distributed Database  The Standard Library  CEAN 93