26
Introducing Erlang March 4, 2015 Anuj Jamwal

Introucing Erlang

Embed Size (px)

Citation preview

Page 1: Introucing Erlang

Introducing Erlang

March 4, 2015

Anuj Jamwal

Page 2: Introucing Erlang

Who are using Erlang?

Page 3: Introucing Erlang
Page 4: Introucing Erlang

Erlang Philosophy

“Erlang was designed for writing concurrent programs that run forever”

- Joe Armstrong

Page 5: Introucing Erlang

What ’s so great about Erlang?

• Great Concurrency Model

• Network Transparency

• Fault Tolerance

• Replace/Update running code

• Good at slicing and dicing network protocols

Page 6: Introucing Erlang

Key idioms

• Functional

• Processes

• Immutable variables

• Recursion

• Pattern Matching

Page 7: Introucing Erlang

Hello World

Page 8: Introucing Erlang

Data Types

• Integers

• Floats

• Binary Data <<“Hello World”>>

• Tuples {10, 10.43, “hello”, <<“bye”>>}

• Lists [10,20,30]

• Atoms error , ‘Point’

• Functions

Page 9: Introucing Erlang

Function

• First class

• Last expression is return value

• map reduce foldl foldr ….

Page 10: Introucing Erlang

Pattern matching

Page 11: Introucing Erlang

Guard Sequence

• Add to Pattern Matching

• Guard with functions

Page 12: Introucing Erlang

Guard Sequence

• Case Statement

Page 13: Introucing Erlang

Guard Sequence

• If Statement

Page 14: Introucing Erlang

Concurrency

• Super Lightweight process

• Shared Nothing

• Pure Message Passing

• Process can block waiting for a message

• Timeout

Page 15: Introucing Erlang

Process

• Creating a process

Page 16: Introucing Erlang

Message Passing

Page 17: Introucing Erlang

Distribution

• Network Transparency

• Messages can be sent across network

• Function invocation on remote machine

• Distribution Types

– Cookie Based

– Socket Based

Page 18: Introucing Erlang

Fault Tolerance

“At scale, even rare events happen frequently”

Page 19: Introucing Erlang

Erlang Approach

Let it Crash

Page 20: Introucing Erlang

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

Page 21: Introucing Erlang

Memory Management

• Garbage collection per process

• Messages are copied to mailbox

• Except large Binaries (> 64 bytes)

Page 22: Introucing Erlang

Ports

• Interface to programs outside beam

• Easy Polyglot eg. C Java Ruby Python …..

Page 23: Introucing Erlang

What sucks about it?

Page 24: Introucing Erlang

What sucks about it?

• String handling

• Library support

• Learning curve

Page 25: Introucing Erlang

References

Page 26: Introucing Erlang

Questions

Thank You