This presentation is
brought to you by CAT
Introduction to Elixir
Programming!
AlSayed Gamal
Lead architect @ Cognitev !
At Cognitev we make the internet a better place
by putting advertising on auto-pilot!
We are hiring!
What’s elixir?
- Functional programming ?
- Running on Erlang VM ?
Why should I care ?
- Supervisor, Actor, OTP
And more..
- Aimed for concurrent application.
Interesting Fact!
At least 50% of your phone calls
are routed through erlang
service!
Erlang Functional
Programming.
(Where functions are first class citizen)
● Higher order functions, Currying, Closure..
● Better to test
● Utilizes multi-core CPUs
● OTP, Supervisor Hot-code swapping,
fault-tolerance.
Fact
Elixir isn’t the only
functional programming
language.
Scala, haskel and lisp
are example for famous
functional programming
languages.
What’s wrong with the OOP?
- Not every problem is a nail not every solution is a
hammer.
- Great OOP communities are migrating to
functional programming paradigm through
languages that are compatible or close in syntax.
- Examples:
F#, Scala, and kotlin
defmodule Greeter do
def greet(name) do
message = "Hello, " <> name <> "!"
IO.puts message
end
end
Greeter.greet("world")
$ elixir hello.exs
$ iex
iex>
Complex hello, world!
Floats 3.14
Ints 100
Atoms :i_am_special_string
Ranges 1..10 #range from 1 to 10
Regex ~r{Gama{1,4}l}
Charlist ‘hello’
Binary String “hello”
iex> ?a
iex> ? ‫أ‬
Value types
Tuples {:ok, “some content}
Linked Lists [1,2,3,4]
Maps %{:key => value} #Rails gedan! iex> hd(list) #1
iex> tl(list) #[2,3,4]
Collection types
PIDs: Node.spawn reference to
local or remote process.
Ports: simply reference to a
port
iex> Node.spawn_link :"foo@computer-name",
fn -> Hello.world end
#PID<9014.59.0>
System Types
X = 10 #bind x
10 = x #pattern match x to 10
[a, b, c] = [1, 2, 3]
[_, _, c] = [1, 2, 3]
def greet(%{name: username}) do
IO.puts "Hello, " <> username
end
user = %{name: "Tom", age: 23}
Pattern Matching
Node1 > on /home/gamal/node1
Node2 > on /home/gamal/node2
What if Node1 wants to spawn
some process to run in the
context of Node2?
iex> Node.list
iex> Node.connect :”node_1@Gamalenovo”
iex> Node.ping :”node_1@Gamalenovo”
iex> Node.spawn(:"node_2@Gamalenovo", func)
Hello, Distributed computing!
● Phoenix
○ Web-framework that’s heavily
inspired by rails.
● OTP
○ It’s not about telecom.
○ It’s about telecom’s high-
availability and fault-tolerance
Supervisor in action!
WHat’s next ?
Sources
https://pragprog.com/book/elixir13/programming-elixir-1-3
https://www.slideshare.net/Diacode/introduction-to-elixir
https://devhints.io/elixir
Thank you!

Elixir introduction

  • 1.
  • 2.
  • 3.
    AlSayed Gamal Lead architect@ Cognitev ! At Cognitev we make the internet a better place by putting advertising on auto-pilot! We are hiring!
  • 4.
    What’s elixir? - Functionalprogramming ? - Running on Erlang VM ? Why should I care ? - Supervisor, Actor, OTP And more.. - Aimed for concurrent application. Interesting Fact! At least 50% of your phone calls are routed through erlang service!
  • 6.
    Erlang Functional Programming. (Where functionsare first class citizen) ● Higher order functions, Currying, Closure.. ● Better to test ● Utilizes multi-core CPUs ● OTP, Supervisor Hot-code swapping, fault-tolerance. Fact Elixir isn’t the only functional programming language. Scala, haskel and lisp are example for famous functional programming languages.
  • 7.
    What’s wrong withthe OOP? - Not every problem is a nail not every solution is a hammer. - Great OOP communities are migrating to functional programming paradigm through languages that are compatible or close in syntax. - Examples: F#, Scala, and kotlin
  • 8.
    defmodule Greeter do defgreet(name) do message = "Hello, " <> name <> "!" IO.puts message end end Greeter.greet("world") $ elixir hello.exs $ iex iex> Complex hello, world!
  • 9.
    Floats 3.14 Ints 100 Atoms:i_am_special_string Ranges 1..10 #range from 1 to 10 Regex ~r{Gama{1,4}l} Charlist ‘hello’ Binary String “hello” iex> ?a iex> ? ‫أ‬ Value types
  • 10.
    Tuples {:ok, “somecontent} Linked Lists [1,2,3,4] Maps %{:key => value} #Rails gedan! iex> hd(list) #1 iex> tl(list) #[2,3,4] Collection types
  • 11.
    PIDs: Node.spawn referenceto local or remote process. Ports: simply reference to a port iex> Node.spawn_link :"foo@computer-name", fn -> Hello.world end #PID<9014.59.0> System Types
  • 12.
    X = 10#bind x 10 = x #pattern match x to 10 [a, b, c] = [1, 2, 3] [_, _, c] = [1, 2, 3] def greet(%{name: username}) do IO.puts "Hello, " <> username end user = %{name: "Tom", age: 23} Pattern Matching
  • 13.
    Node1 > on/home/gamal/node1 Node2 > on /home/gamal/node2 What if Node1 wants to spawn some process to run in the context of Node2? iex> Node.list iex> Node.connect :”node_1@Gamalenovo” iex> Node.ping :”node_1@Gamalenovo” iex> Node.spawn(:"node_2@Gamalenovo", func) Hello, Distributed computing!
  • 14.
    ● Phoenix ○ Web-frameworkthat’s heavily inspired by rails. ● OTP ○ It’s not about telecom. ○ It’s about telecom’s high- availability and fault-tolerance Supervisor in action! WHat’s next ?
  • 15.
  • 16.