Upload
anuj-jamwal
View
163
Download
0
Tags:
Embed Size (px)
Citation preview
Introducing Erlang
March 4, 2015
Anuj Jamwal
Who are using Erlang?
Erlang Philosophy
“Erlang was designed for writing concurrent programs that run forever”
- Joe Armstrong
What ’s so great about Erlang?
• Great Concurrency Model
• Network Transparency
• Fault Tolerance
• Replace/Update running code
• Good at slicing and dicing network protocols
Key idioms
• Functional
• Processes
• Immutable variables
• Recursion
• Pattern Matching
Hello World
Data Types
• Integers
• Floats
• Binary Data <<“Hello World”>>
• Tuples {10, 10.43, “hello”, <<“bye”>>}
• Lists [10,20,30]
• Atoms error , ‘Point’
• Functions
Function
• First class
• Last expression is return value
• map reduce foldl foldr ….
Pattern matching
Guard Sequence
• Add to Pattern Matching
• Guard with functions
Guard Sequence
• Case Statement
Guard Sequence
• If Statement
Concurrency
• Super Lightweight process
• Shared Nothing
• Pure Message Passing
• Process can block waiting for a message
• Timeout
Process
• Creating a process
Message Passing
Distribution
• Network Transparency
• Messages can be sent across network
• Function invocation on remote machine
• Distribution Types
– Cookie Based
– Socket Based
Fault Tolerance
“At scale, even rare events happen frequently”
Erlang Approach
Let it Crash
Erlang Approach
• If you can’t do what you want to do, die.
• Do not program defensively.
• Let some other process do the error recovery.
• Let it crash
Memory Management
• Garbage collection per process
• Messages are copied to mailbox
• Except large Binaries (> 64 bytes)
Ports
• Interface to programs outside beam
• Easy Polyglot eg. C Java Ruby Python …..
What sucks about it?
What sucks about it?
• String handling
• Library support
• Learning curve
References
Questions
Thank You