SlideShare a Scribd company logo
Erlang/OTP
for Rubyists
    Sean Cribbs
  KC.rb - July 2009
Ruby


Makes easy things trivial
  and hard things fun!
Erlang


 Makes easy things possible
and impossible things trivial!


     Orion Henry and Blake Mizerany
               (Heroku)
What is Erlang?

•Language, Runtime and Libraries (OTP)
•Developed and maintained by Ericsson
•Started mid 1980s, open-sourced 1998
Who uses it?
Who uses it?
Object-oriented
 Programming
object               object                   object
            object              object
                                                       object
 object                                    object
              object          object
object                                               object
         Object-oriented
  object  Programming                                object
  object                                    object
                     object       object
          object                                       object
                                           object
                        object
Object-oriented
 Programming
Concurrency-oriented
   Programming
process                  process
      process              process
                                                 process
process                                process
            process    process
                                            process
process                         process

   Concurrency-oriented
process
        Programming  process
  process                                 process
                             process
            process                           process
                      process
  process                              process
Concurrency-oriented
   Programming
Fault-tolerance
      IFF
 Concurrency
Error Handling

    Intra-process
    Inter-process
   Inter-machine
Sharing doesn’t scale
•Deadlocks
•Race Conditions
•Starvation
•Synchronization
•Data Locality
•Corruption
Message passing
 is the answer
Cool Features
•Concurrent
•Distributed
•Share-nothing
•Fault-tolerant
•Hot upgrades
•Highly available
Big Differences

•Functional - no objects
•Single assignment, few side-effects
•Initially challenging syntax
•Nothing like gems
Are you ready to be
UNCOMFORTABLY
  PARALLEL?
Spawn

Pid = spawn(
     fun()->
       io:format("Hello, Joe.")
     end).
Send Messages


  Pid ! {greet, “Joe”}.
Receive Messages
loop() ->
  receive
   {greet,S} ->
     io:format(“Hello, ~s”, [S]),
     loop();
   stop -> ok;
   _ -> loop()
  end.
Syntax Overview
Numbers

               1
             -1
           2501
            3.14
12345678987654321.987654321
Atoms

    foo
  type
  true
  false
 ‘EXIT’
Lists


        [1,2,3]
[“dog”, “cat”, “fish”]
   “hello, world”
Tuples
             {name, “Sean”}

{address, “8700 State Line Rd”, “Leawood”,
                   “KS”}

         {{line, 10},{column,30}}

          {{2009,7,14},{19,0,0}}
Binaries

           <<“chunk of bytes”>>

<<131,108,0,0,0,2,100,0,3,111,110,101,100
           ,0,3,116,119,111,
                  106>>
Some Weirdos

“abc” == [97,98,99]. % lists of bytes

true, false % atoms

$a == 97. % characters (ASCII)

P#person.name % compile-time struct
Assignment
Pattern Matching
Pattern Matching

         A = 5.

        B = 10.

    Group = “KC.rb”.
Pattern Matching

{Type, Value} = {username, “sean”}.

[{username, Value},
 {orders, Orders}] = [{username, “sean”},
              {orders, [1,2,3]}].
Single Assignment
    Really, this is just pattern matching.



A = 5.

A = A + 1. % error: badmatch (5 = 6)
Lists
functional programming’s old friend
List Operations

[First|Rest] = [1,2,3,4,5].

[H|T] = [1,2,3,4,5].

List1 ++ List2.
List Comprehensions
           Think select/filter + map.


A = [1,2,3,4,5].

[X * 2 || X <- A]. % [2,4,6,8,10]

[X || X <- A, X rem 2 == 0]. % [2,4]
Functions

even_or_odd(Num) ->
 if
   Num rem 2 == 0 ->
     even;
   true ->
     odd
 end.
Functions

even_or_odd(N) when N rem 2 == 0 ->
 even;

even_or_odd(N) ->
 odd.
Functions

even_or_odd(N) when is_number(N),
         N rem 2 == 0 ->
 even;

even_or_odd(N) when is_number(N) ->
 odd.
Anonymous Functions
           like lambda/proc, block


Double = fun(X) -> 2*X end.

Double(2). % 4

lists:map(Double, [1,2,3,4,5]).
  % [2,4,6,8,10]
No Loops!
 use recursion
A Little CS Theorem
   iterative === recursive
List “iteration”

print([]) ->
 ok;
print([H|T]) ->
 io:format(“~p”, [H]),
 print(T).
List “iteration”

print([]) ->
 ok;
print([H|T]) ->
 io:format(“~p”, [H]),
 print(T).
 print(T).
Normal Recursion
  loop()



           loop()



                    loop()



                             loop()
Tail Recursion
(aka tail-call optimization)




           loop()
Concurrent programs
can be complicated.
Behaviors
               “patterns”



•gen_server - client-server
•gen_fsm - state machine
•supervisor - fault-tolerance
How does it scale?

•Micro-benchmarks, arithmetic slow
•Best for network(ed) apps
•Campfire just as fast as C, ~ 2-4ms
•Near-linear speedup on multicores
•GC per-process, generational
Sean ! Questions.

More Related Content

What's hot

Programming in Computational Biology
Programming in Computational BiologyProgramming in Computational Biology
Programming in Computational Biology
AtreyiB
 
Slides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammersSlides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammers
Giovanni924
 

What's hot (20)

Python language data types
Python language data typesPython language data types
Python language data types
 
Introduction to the basics of Python programming (part 3)
Introduction to the basics of Python programming (part 3)Introduction to the basics of Python programming (part 3)
Introduction to the basics of Python programming (part 3)
 
Advanced Python, Part 2
Advanced Python, Part 2Advanced Python, Part 2
Advanced Python, Part 2
 
Advanced Python, Part 1
Advanced Python, Part 1Advanced Python, Part 1
Advanced Python, Part 1
 
Programming in Computational Biology
Programming in Computational BiologyProgramming in Computational Biology
Programming in Computational Biology
 
Coding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean CodeCoding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean Code
 
Strings in python
Strings in pythonStrings in python
Strings in python
 
Python and sysadmin I
Python and sysadmin IPython and sysadmin I
Python and sysadmin I
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
 
Matlab and Python: Basic Operations
Matlab and Python: Basic OperationsMatlab and Python: Basic Operations
Matlab and Python: Basic Operations
 
Python fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuanPython fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuan
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
 
Slides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammersSlides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammers
 
Python in 90 minutes
Python in 90 minutesPython in 90 minutes
Python in 90 minutes
 
Python
PythonPython
Python
 
Introduction to Python and TensorFlow
Introduction to Python and TensorFlowIntroduction to Python and TensorFlow
Introduction to Python and TensorFlow
 
Learn python in 20 minutes
Learn python in 20 minutesLearn python in 20 minutes
Learn python in 20 minutes
 
Introduction to Perl and BioPerl
Introduction to Perl and BioPerlIntroduction to Perl and BioPerl
Introduction to Perl and BioPerl
 
Clean code
Clean codeClean code
Clean code
 

Similar to Erlang/OTP for Rubyists

Migrating from matlab to python
Migrating from matlab to pythonMigrating from matlab to python
Migrating from matlab to python
ActiveState
 
Logic Programming and ILP
Logic Programming and ILPLogic Programming and ILP
Logic Programming and ILP
Pierre de Lacaze
 

Similar to Erlang/OTP for Rubyists (20)

Python: The Dynamic!
Python: The Dynamic!Python: The Dynamic!
Python: The Dynamic!
 
Elixir
ElixirElixir
Elixir
 
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
 
Migrating from matlab to python
Migrating from matlab to pythonMigrating from matlab to python
Migrating from matlab to python
 
app4.pptx
app4.pptxapp4.pptx
app4.pptx
 
DEFCON 23 - Mike Sconzo - i am packer and so can you
DEFCON 23 - Mike Sconzo - i am packer and so can youDEFCON 23 - Mike Sconzo - i am packer and so can you
DEFCON 23 - Mike Sconzo - i am packer and so can you
 
Functional (web) development with Clojure
Functional (web) development with ClojureFunctional (web) development with Clojure
Functional (web) development with Clojure
 
Ruby1_full
Ruby1_fullRuby1_full
Ruby1_full
 
Ruby1_full
Ruby1_fullRuby1_full
Ruby1_full
 
Long Live the Rubyist
Long Live the RubyistLong Live the Rubyist
Long Live the Rubyist
 
Poetic APIs
Poetic APIsPoetic APIs
Poetic APIs
 
Dynamic Python
Dynamic PythonDynamic Python
Dynamic Python
 
Erlang intro
Erlang introErlang intro
Erlang intro
 
The Proxy Fairy, and The Magic of Spring Framework
The Proxy Fairy, and The Magic of Spring FrameworkThe Proxy Fairy, and The Magic of Spring Framework
The Proxy Fairy, and The Magic of Spring Framework
 
Sugar Presentation - YULHackers March 2009
Sugar Presentation - YULHackers March 2009Sugar Presentation - YULHackers March 2009
Sugar Presentation - YULHackers March 2009
 
Python programming
Python programmingPython programming
Python programming
 
Ruby and rails - Advanced Training (Cybage)
Ruby and rails - Advanced Training (Cybage)Ruby and rails - Advanced Training (Cybage)
Ruby and rails - Advanced Training (Cybage)
 
Logic Programming and ILP
Logic Programming and ILPLogic Programming and ILP
Logic Programming and ILP
 
Effective Object Oriented Design in Cpp
Effective Object Oriented Design in CppEffective Object Oriented Design in Cpp
Effective Object Oriented Design in Cpp
 
Architecting Scalable Platforms in Erlang/OTP | Hamidreza Soleimani | Diginex...
Architecting Scalable Platforms in Erlang/OTP | Hamidreza Soleimani | Diginex...Architecting Scalable Platforms in Erlang/OTP | Hamidreza Soleimani | Diginex...
Architecting Scalable Platforms in Erlang/OTP | Hamidreza Soleimani | Diginex...
 

More from Sean Cribbs

Riak (Øredev nosql day)
Riak (Øredev nosql day)Riak (Øredev nosql day)
Riak (Øredev nosql day)
Sean Cribbs
 
Introduction to Riak and Ripple (KC.rb)
Introduction to Riak and Ripple (KC.rb)Introduction to Riak and Ripple (KC.rb)
Introduction to Riak and Ripple (KC.rb)
Sean Cribbs
 
Content Management That Won't Rot Your Brain
Content Management That Won't Rot Your BrainContent Management That Won't Rot Your Brain
Content Management That Won't Rot Your Brain
Sean Cribbs
 

More from Sean Cribbs (18)

Eventually Consistent Data Structures (from strangeloop12)
Eventually Consistent Data Structures (from strangeloop12)Eventually Consistent Data Structures (from strangeloop12)
Eventually Consistent Data Structures (from strangeloop12)
 
Eventually-Consistent Data Structures
Eventually-Consistent Data StructuresEventually-Consistent Data Structures
Eventually-Consistent Data Structures
 
A Case of Accidental Concurrency
A Case of Accidental ConcurrencyA Case of Accidental Concurrency
A Case of Accidental Concurrency
 
Embrace NoSQL and Eventual Consistency with Ripple
Embrace NoSQL and Eventual Consistency with RippleEmbrace NoSQL and Eventual Consistency with Ripple
Embrace NoSQL and Eventual Consistency with Ripple
 
Riak with node.js
Riak with node.jsRiak with node.js
Riak with node.js
 
Schema Design for Riak (Take 2)
Schema Design for Riak (Take 2)Schema Design for Riak (Take 2)
Schema Design for Riak (Take 2)
 
Riak (Øredev nosql day)
Riak (Øredev nosql day)Riak (Øredev nosql day)
Riak (Øredev nosql day)
 
Riak Tutorial (Øredev)
Riak Tutorial (Øredev)Riak Tutorial (Øredev)
Riak Tutorial (Øredev)
 
The Radiant Ethic
The Radiant EthicThe Radiant Ethic
The Radiant Ethic
 
Introduction to Riak and Ripple (KC.rb)
Introduction to Riak and Ripple (KC.rb)Introduction to Riak and Ripple (KC.rb)
Introduction to Riak and Ripple (KC.rb)
 
Riak with Rails
Riak with RailsRiak with Rails
Riak with Rails
 
Schema Design for Riak
Schema Design for RiakSchema Design for Riak
Schema Design for Riak
 
Introduction to Riak - Red Dirt Ruby Conf Training
Introduction to Riak - Red Dirt Ruby Conf TrainingIntroduction to Riak - Red Dirt Ruby Conf Training
Introduction to Riak - Red Dirt Ruby Conf Training
 
Introducing Riak and Ripple
Introducing Riak and RippleIntroducing Riak and Ripple
Introducing Riak and Ripple
 
Story Driven Development With Cucumber
Story Driven Development With CucumberStory Driven Development With Cucumber
Story Driven Development With Cucumber
 
Achieving Parsing Sanity In Erlang
Achieving Parsing Sanity In ErlangAchieving Parsing Sanity In Erlang
Achieving Parsing Sanity In Erlang
 
Of Rats And Dragons
Of Rats And DragonsOf Rats And Dragons
Of Rats And Dragons
 
Content Management That Won't Rot Your Brain
Content Management That Won't Rot Your BrainContent Management That Won't Rot Your Brain
Content Management That Won't Rot Your Brain
 

Recently uploaded

Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 

Recently uploaded (20)

Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
In-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsIn-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT Professionals
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
 

Erlang/OTP for Rubyists