Upgrade to Pro — share decks privately, control downloads, hide ads and more …

A Chat About Erlang

A Chat About Erlang

Bryce "BonzoESC" Kerley

February 19, 2013
Tweet

More Decks by Bryce "BonzoESC" Kerley

Other Decks in Programming

Transcript

  1. Disclaimer The thoughts, views, and opinions in this presentation are

    mine, and not my employer’s. Monday, February 18, 13
  2. 1> X = 5. 5 2> Y = X. 5

    3> 5 = Y. 5 4> Y = 6. ** exception error: no match Erlang is Functional Monday, February 18, 13
  3. 5 3> 5 = Y. 5 4> Y = 6.

    ** exception error: no match 5> Z = fun(N) -> N * 2 end. #Fun<erl_eval.6.80247286> 6> Z. #Fun<erl_eval.6.80247286> 7> Z(5). 10 Erlang is Functional Monday, February 18, 13
  4. Erlang is Reliable Illustration by Fred Hébert, from “Learn You

    Some Erlang for Great Good!” Monday, February 18, 13
  5. Pattern Matching More useful than equality More powerful than method

    overloading describe_error(Desc,  [],  [trashed])  -­‐>   {obserror,  Desc}; describe_error(Desc,  [],  Stack)  -­‐>   {obserror,  format("~s.  Stack  ~w",  [Desc,  Stack])}; describe_error(Desc,  Rest,  Stack)  -­‐>   {obserror,  format("~s.    Rest:  ~w  Stack  ~w",  [Desc,  Rest,  Stack])}. Monday, February 18, 13
  6. Data Types •Fun: anonymous function, closure •Reference: unique ID •Port

    identifier: pointer to an I/O port •Pid: pointer to an Erlang process Monday, February 18, 13
  7. Synthetic Data Types •Binary: a Bit String with a multiple

    of 8 bits •String: a List of Integers •Record: a Tuple enforced by the compiler •IO List: a List of Integers, Binaries, and IO Lists; or a Binary •Boolean: the atoms true and false Monday, February 18, 13
  8. Environment •Process: similar to a thread •Module: collection of functions

    •Macro: preprocessor facility (like C) Monday, February 18, 13
  9. Process •No shared memory •Asynchronous messaging •Garbage collected independently •Fast

    to create, fast to destroy •Low overhead Monday, February 18, 13
  10. Open Telecom Platform Illustration by Fred Hébert, from “Learn You

    Some Erlang for Great Good!” Monday, February 18, 13
  11. Behaviors Similar to Ruby mixins Think Enumerable You implement callbacks

    Behavior supplies the rest Monday, February 18, 13
  12. gen_server You Write It Does init turns arguments into state

    handle_call synchronous, respond and new state handle_cast asynchronous, new state handle_info timeout, new state terminate clean up code_change just upgraded, new state Monday, February 18, 13
  13. gen_server State: whatever you want Last argument Last element in

    response tuple handle_call(all_vnodes_status,  _From,  State)  -­‐>        Reply  =  get_all_vnodes_status(State),        {reply,  Reply,  State}; https://github.com/basho/riak_core/blob/1276e4e926b7007262f7631a27cdb4ecf6cbcaaf/src/riak_core_vnode_manager.erl#L260-L262 Monday, February 18, 13
  14. Other Behaviors gen_fsm: finite state machine gen_event: event dispatch and

    handling supervisor: keep trees of servers, fsms, events, etc. alive Monday, February 18, 13
  15. Riak Open-source database Built with Erlang, OTP, rebar, webmachine Great

    for sanity checking implementation Monday, February 18, 13
  16. What is Erlang bad at? Prolog syntax Opinionated rules No

    Rails-tier web frameworks Monday, February 18, 13
  17. What is Ruby good at? Friendly syntax Few rules, lots

    of customizability Great frameworks Monday, February 18, 13