SlideShare ist ein Scribd-Unternehmen logo
1 von 95
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Andere mochten auch

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-SubramanyaHakka 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
 
VoltDB and Erlang - Tech planet 2012
VoltDB and Erlang - Tech planet 2012VoltDB and Erlang - Tech planet 2012
VoltDB and Erlang - Tech planet 2012Eonblast
 
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 NeedsTorben Hoffmann
 
Elixir for aspiring Erlang developers
Elixir for aspiring Erlang developersElixir for aspiring Erlang developers
Elixir for aspiring Erlang developersTorben Dohrn
 
Clojure Intro
Clojure IntroClojure Intro
Clojure Introthnetos
 
Elixir Into Production
Elixir Into ProductionElixir Into Production
Elixir Into ProductionJamie Winsor
 
Clojure: Towards The Essence of Programming
Clojure: Towards The Essence of ProgrammingClojure: Towards The Essence of Programming
Clojure: Towards The Essence of ProgrammingHoward Lewis Ship
 
Clojure, Plain and Simple
Clojure, Plain and SimpleClojure, Plain and Simple
Clojure, Plain and SimpleBen Mabey
 
Clojure for Data Science
Clojure for Data ScienceClojure for Data Science
Clojure for Data ScienceMike Anderson
 
Clojure for Java developers
Clojure for Java developersClojure for Java developers
Clojure for Java developersJohn Stevenson
 
Erlang - Concurrent Language for Concurrent World
Erlang - Concurrent Language for Concurrent WorldErlang - Concurrent Language for Concurrent World
Erlang - Concurrent Language for Concurrent WorldZvi Avraham
 
Functional programming in clojure
Functional programming in clojureFunctional programming in clojure
Functional programming in clojureJuan-Manuel Gimeno
 
Basic Study for Erlang #2
Basic Study for Erlang #2Basic Study for Erlang #2
Basic Study for Erlang #2Masahito 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
 

Andere mochten auch (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
 

Ähnlich wie Introduction to Erlang for Python Programmers

Confusing introduction to elixir
Confusing introduction to elixirConfusing introduction to elixir
Confusing introduction to elixirLauri 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 Germanymomo-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 CRubyMatthew 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
 
Origins of Elixir programming language
Origins of Elixir programming languageOrigins of Elixir programming language
Origins of Elixir programming languagePivorak MeetUp
 
Rubinius - A Tool of the Future
Rubinius - A Tool of the FutureRubinius - A Tool of the Future
Rubinius - A Tool of the Futureevanphx
 
An intro to programming
An intro to programmingAn intro to programming
An intro to programmingWolfFlight
 
Sugar Presentation - YULHackers March 2009
Sugar Presentation - YULHackers March 2009Sugar Presentation - YULHackers March 2009
Sugar Presentation - YULHackers March 2009spierre
 
TRICK2013 Results
TRICK2013 ResultsTRICK2013 Results
TRICK2013 Resultsmametter
 
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 GoOliver N
 
arduino
arduinoarduino
arduinomurbz
 
[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 AnalysisMoabi.com
 
An introduction to erlang
An introduction to erlangAn introduction to erlang
An introduction to erlangMirko 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 AnalysisMoabi.com
 

Ähnlich wie 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
 

Mehr von 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, whatPython 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 PythonPython 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 PythonPython 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 environmentPython 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 experiencePython Ireland
 
Python Ireland Nov 2009 Talk - Appengine
Python Ireland Nov 2009 Talk - AppenginePython Ireland Nov 2009 Talk - Appengine
Python Ireland Nov 2009 Talk - AppenginePython 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 TestingPython 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 DjangoPython 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 PythonPython 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 BoltsPython Ireland
 
Python for cloud computing
Python for cloud computingPython for cloud computing
Python for cloud computingPython Ireland
 
IPython: The awesome python shell
IPython: The awesome python shellIPython: The awesome python shell
IPython: The awesome python shellPython Ireland
 

Mehr von 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
 

Kürzlich hochgeladen

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 

Kürzlich hochgeladen (20)

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

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