Your SlideShare is downloading. ×
0
The Erlang Programming Language
The Erlang Programming Language
The Erlang Programming Language
The Erlang Programming Language
The Erlang Programming Language
The Erlang Programming Language
The Erlang Programming Language
The Erlang Programming Language
The Erlang Programming Language
The Erlang Programming Language
The Erlang Programming Language
The Erlang Programming Language
The Erlang Programming Language
The Erlang Programming Language
The Erlang Programming Language
The Erlang Programming Language
The Erlang Programming Language
The Erlang Programming Language
The Erlang Programming Language
The Erlang Programming Language
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

The Erlang Programming Language

2,259

Published on

Published in: Technology, News & Politics
1 Comment
2 Likes
Statistics
Notes
No Downloads
Views
Total Views
2,259
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
90
Comments
1
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. The Erlang Programming Language Dennis Byrne - ThoughtWorks [email_address] http://notdennisbyrne.blogspot.com/ © ThoughtWorks 2008
  • 2. Introduction
    • Not a “shiny new object (or function)”
    • Open sourced by Ericsson
    • Functional Programming
    • Concurrency
    • Reliability
    • ThoughtWorks ! Erlang
    © ThoughtWorks 2008 Erlang is a functional programming language, with native constructs for concurrency and reliability.
  • 3. A Totally “Unbiased” Comparison
    • In Erlang:
    • List = [1,2,3,4,5].
    • Doubled = lists:map( fun(I) -> I * 2 end, List).
    • In Java:
    • List<Integer> list = new LinkedList<Integer>() {{
    • add(1); add(2); add(3); add(4); add(5);
    • }};
    • List<Integer> doubled = new ArrayList<Integer>();
    • for(Integer integer : list) {
    • doubled.add(integer.intValue() * 2);
    • }
    © ThoughtWorks 2008
  • 4. Single Assignment & Unification
    • I = 4. % assignment
    • I = 4. % unification
    • I = I. % unification
    • 4 = I. % unification
    • I = 5. % throws error :(
    © ThoughtWorks 2008
  • 5. Pattern Matching
    • 1> MyList = [ “ A ” ]. % declaring a list
    • 2> [Var] = MyList. % implicit declaration
    • 3> io:format(Var). % prints “ A ”
    • 1> MyList = [ “ A ” , “ B ” ]. % declaring a list
    • 2> [_, Var] = MyList. % _ is ignored
    • 3> io:format(Var). % prints B
    © ThoughtWorks 2008
  • 6. Functions as First Class Citizens
    • 1> Msg = &quot;I am scoped&quot;.
    • 2> F = fun()->
    • io:format(Msg)
    • end.
    • 3> F(). % prints “ I am scoped ”
    © ThoughtWorks 2008
  • 7. Tail Recursion
    • Tail recursion is to ‘recursion’ as optimistic locking is to ‘locking’.
    • loop() ->
    • io:format( “ in constant space ” ),
    • loop() .
    • Automatic byte code manipulation
    • Last call optimization
    © ThoughtWorks 2008
  • 8. Pop Quiz: Evaluation Strategies
    • f( a(), b() )
    • Order of evaluation
    • Lazy or strict?
    • Left, right, both, neither?
    © ThoughtWorks 2008
  • 9. State
    • Erlang avoids complex solutions in favor of simple ways to avoid the problem
    • State is immutable w/ single assignment
    • State is private, passed by value
    • Changing Perspectives
      • Contention vs. Scale
      • Side Effects vs. Scale
    © ThoughtWorks 2008
  • 10. Erlang Process
    • An Erlang process combines the best of
      • An operating system process
      • An operating system thread
      • A “green thread”
    • Controlled in user space by the ERTS
    • Costs less than 300 bytes
      • Private heap
      • Private stack
    • All processes are created equal
    • Incremental garbage collection
    © ThoughtWorks 2008
  • 11. The Actor Model
    • Asynchronous Message passing
    • Messages passed by value, not reference
    • One to one relationship
      • An Actor
      • A mailbox
      • A Process
      • A Process ID, or pid
    © ThoughtWorks 2008
  • 12. Concurrency Primitives: spawn
    • A built in function used to create a process.
    • Pid = spawn(Node, Module, Function, Args)
    © ThoughtWorks 2008
  • 13. Another “Unbiased” Comparison
    • In Erlang:
    • Pid = spawn(fun() -> io:format(“hello world”) end).
    • In Java:
    • Thread thread = new Thread() {
    • public void run() {
    • System.out.println(&quot;Hello World&quot;);
    • }
    • }.start();
    © ThoughtWorks 2008
  • 14. Concurrency Primitives: send
    • !
    © ThoughtWorks 2008
  • 15. Concurrency Primitives: send
    • The send operator passes a message to a process. It is “fire and forget”.
    • Pid ! Msg
    © ThoughtWorks 2008
  • 16. Concurrency Primitives: receive
    • receive
    • Pattern1 [ when Guard1 ] ->
    • dosomething().
    • Pattern2 [ when Guard2 ] ->
    • dosomethingelse().
    • end
    © ThoughtWorks 2008
  • 17. Reliability
    • catch
    • try
    • Monitor
      • monitor_node(Node, Bool)
      • Unidirectional
    • Link
      • Pid = spawn_link(Node, Module, Fun, Args)
      • Bi-directional
    © ThoughtWorks 2008
  • 18. The Opposite of Ruby © ThoughtWorks 2008 Erlang Ruby Orientation Functional Object Syntax Ugly Beautiful Concurrent Good Bad Track Record Back end Front end Execution Model Compiled Interpreted
  • 19. Erlang Servers and Frameworks
    • Mnesia – distributed database
    • YAWS – “yet another web server”
    • ErlyWeb – MVC web framework
    • EUnit
    • Jungerl – third party libraries
    • Perferl ( http://code.google.com/p/perferl )
    © ThoughtWorks 2008
  • 20. The Erlang Programming Language
    • Dennis Byrne - ThoughtWorks
    • [email_address]
    • http://notdennisbyrne.blogspot.com/
    © ThoughtWorks 2008

×