Programming Erlang

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

    1 Favorite

    Programming Erlang - Presentation Transcript

    1. Programming Erlang June 17, 2009 Ken Pratt http://kenpratt.net/
    2. Erlang philosophy Simple language Ultra-lightweight concurrency No shared state (and no locks, no mutexes) <3 asynchronous message passing Processes should be able to run forever
    3. The language Functional Strong, dynamic typing NO shared state(!!) (and no mutable variables) Pattern matching on steroids <3 tail recursion Compiled to bytecode, runs on VM
    4. Basic data types Integers Floats Atoms Tuples Lists
    5. Integers No maximum size (a growing integer will keep eating memory until you run out of RAM -- that’s a big number!)
    6. Floating-point numbers 64-bit precision
    7. Atoms Non-numerical constants Like Ruby symbols “Natural” atoms: [a-z][a-zA-Z0-9_@]+ Otherwise, anything single-quoted is an atom
    8. Tuples Fixed-length sets of elements Used sort of like C/C++ structs, for passing structured data around
    9. Lists Variable-length collections of elements Usually homogenous, but can be heterogeneous (like Ruby) Library of list operations (foreach, map, filter, sort, etc)
    10. NOT Types Booleans Strings (oh dear!!) Hashes Classes & objects ;)
    11. Booleans Just a special case of atoms
    12. Strings Just a list of integers in the range 0..255 Double quotes are syntactic sugar Unicode support added March 2009 in Erlang R13A io:format and io_lib:format for printf-like formatting
    13. Hash tables/dictionaries Property list Just a list of two-element tuples “proplists” library has common functionality “dict” library is a heavier, more feature-full option
    14. Classes & objects Erlang is functional, and doesn’t have classes/objects However, it has records, which are a “named tuple” They are a compile-time feature, which is ANNOYING
    15. Functions Named functions & anonymous functions (funs) Differ by arity (convention is [func_name/arity]) myfun/1 and myfun/2 are different functions
    16. Pattern matching Pattern matching is awesome “=” is NOT an assignment operator! It is a pattern match operator Unbound variables will get bound during the match
    17. Nested patterns You can match nested structures
    18. Matching list elements It’s easy to grab one or more elements from a list
    19. Matching function clauses Can have multiple named functions with the same arity, using pattern matching on arguments
    20. Matching + functions
    21. Conditionals Supports case and if statements, but they are very different from other languages Both have pattern matching support Both use “guards”, which are simple operations like comparisons (<, >, etc), is_atom, length(List), etc
    22. Case statements
    23. If statements Avoid them, as case is cleaner, even for true/false
    24. Processes Erlang processes are sort of like threads, but without the headaches of shared state
    25. Messages Each process has a message queue Easy to send messages around Common convention is to send a tuple where first element is an atom with the message type
    26. Receiving messages Use a receive block to pull a message off the queue Usual pattern is a server “loop” that waits for messages
    27. Synchronous messages Asynchronous by default But easy to implement synchronous messages Need to pass own pid along with message, so server can reply (self() returns pid of current process)
    28. Actor model Erlang is built around the Actor model Think of a process like an object It handles incoming messages (like calling methods with arguments) It sends replies (like method return values) It incapsulates state (passed around explicitly)
    29. Architecture = light-weight process with a built-in mailbox
    30. Distributed architecture = light-weight process with a built-in mailbox
    31. Networking patterns Erlang has built-in functions for common network operations, such as RPC OTP (“Open Telecom Platform”) libraries provide frameworks for many architecture patterns, such as servers and state machines gen_server is most common -- supports synchronous and asynchronous calls, and server state
    32. Where to start “Programming Erlang” by Joe Armstrong (creator of Erlang) Slides & videos online! (I’ll post the link to the mailing list) http://www.erlang-factory.com/ conference/SFBayAreaErlangFactory2009

    + Ken PrattKen Pratt, 5 months ago

    custom

    680 views, 1 favs, 0 embeds more stats

    (Given to the Vancouver Ruby/Rails Meetup group on more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 680
      • 680 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 1
    • Downloads 29
    Most viewed embeds

    more

    All embeds

    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