Erlang/OTP for Rubyists

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    4 Favorites

    Erlang/OTP for Rubyists - Presentation Transcript

    1. Erlang/OTP for Rubyists Sean Cribbs KC.rb - July 2009
    2. Ruby Makes easy things trivial and hard things fun!
    3. Erlang Makes easy things possible and impossible things trivial! Orion Henry and Blake Mizerany (Heroku)
    4. What is Erlang? •Language, Runtime and Libraries (OTP) •Developed and maintained by Ericsson •Started mid 1980s, open-sourced 1998
    5. Who uses it?
    6. Who uses it?
    7. Object-oriented Programming
    8. 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
    9. Object-oriented Programming
    10. Concurrency-oriented Programming
    11. 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
    12. Concurrency-oriented Programming
    13. Fault-tolerance IFF Concurrency
    14. Error Handling Intra-process Inter-process Inter-machine
    15. Sharing doesn’t scale •Deadlocks •Race Conditions •Starvation •Synchronization •Data Locality •Corruption
    16. Message passing is the answer
    17. Cool Features •Concurrent •Distributed •Share-nothing •Fault-tolerant •Hot upgrades •Highly available
    18. Big Differences •Functional - no objects •Single assignment, few side-effects •Initially challenging syntax •Nothing like gems
    19. Are you ready to be UNCOMFORTABLY PARALLEL?
    20. Spawn Pid = spawn( fun()-> io:format("Hello, Joe.") end).
    21. Send Messages Pid ! {greet, “Joe”}.
    22. Receive Messages loop() -> receive {greet,S} -> io:format(“Hello, ~s”, [S]), loop(); stop -> ok; _ -> loop() end.
    23. Syntax Overview
    24. Numbers 1 -1 2501 3.14 12345678987654321.987654321
    25. Atoms foo type true false ‘EXIT’
    26. Lists [1,2,3] [“dog”, “cat”, “fish”] “hello, world”
    27. Tuples {name, “Sean”} {address, “8700 State Line Rd”, “Leawood”, “KS”} {{line, 10},{column,30}} {{2009,7,14},{19,0,0}}
    28. Binaries <<“chunk of bytes”>> <<131,108,0,0,0,2,100,0,3,111,110,101,100 ,0,3,116,119,111, 106>>
    29. Some Weirdos “abc” == [97,98,99]. % lists of bytes true, false % atoms $a == 97. % characters (ASCII) P#person.name % compile-time struct
    30. Assignment
    31. Pattern Matching
    32. Pattern Matching A = 5. B = 10. Group = “KC.rb”.
    33. Pattern Matching {Type, Value} = {username, “sean”}. [{username, Value}, {orders, Orders}] = [{username, “sean”}, {orders, [1,2,3]}].
    34. Single Assignment Really, this is just pattern matching. A = 5. A = A + 1. % error: badmatch (5 = 6)
    35. Lists functional programming’s old friend
    36. List Operations [First|Rest] = [1,2,3,4,5]. [H|T] = [1,2,3,4,5]. List1 ++ List2.
    37. 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]
    38. Functions even_or_odd(Num) -> if Num rem 2 == 0 -> even; true -> odd end.
    39. Functions even_or_odd(N) when N rem 2 == 0 -> even; even_or_odd(N) -> odd.
    40. Functions even_or_odd(N) when is_number(N), N rem 2 == 0 -> even; even_or_odd(N) when is_number(N) -> odd.
    41. 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]
    42. No Loops! use recursion
    43. A Little CS Theorem iterative === recursive
    44. List “iteration” print([]) -> ok; print([H|T]) -> io:format(“~p”, [H]), print(T).
    45. List “iteration” print([]) -> ok; print([H|T]) -> io:format(“~p”, [H]), print(T). print(T).
    46. Normal Recursion loop() loop() loop() loop()
    47. Tail Recursion (aka tail-call optimization) loop()
    48. Concurrent programs can be complicated.
    49. Behaviors “patterns” •gen_server - client-server •gen_fsm - state machine •supervisor - fault-tolerance
    50. 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
    51. Sean ! Questions.
    SlideShare Zeitgeist 2009

    + Sean CribbsSean Cribbs Nominate

    custom

    1104 views, 4 favs, 1 embeds more stats

    An introduction to Erlang I gave to the Kansas City more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 1104
      • 1006 on SlideShare
      • 98 from embeds
    • Comments 0
    • Favorites 4
    • Downloads 0
    Most viewed embeds
    • 98 views on http://seancribbs.com

    more

    All embeds
    • 98 views on http://seancribbs.com

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories