Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Why Elixir? (Intro to Elixir)
Search
Ventsislav Nikolov
May 22, 2017
Technology
2
150
Why Elixir? (Intro to Elixir)
A brief introduction of Elixir. Level: beginners.
Ventsislav Nikolov
May 22, 2017
Tweet
Share
More Decks by Ventsislav Nikolov
See All by Ventsislav Nikolov
Building Multiplayer Real-Time Game with Elixir and Phoenix
ventsislaf
4
2.3k
Other Decks in Technology
See All in Technology
いざ、BSC討伐の旅
nikinusu
2
780
【Startup CTO of the Year 2024 / Audience Award】アセンド取締役CTO 丹羽健
niwatakeru
0
950
Exadata Database Service on Dedicated Infrastructure(ExaDB-D) UI スクリーン・キャプチャ集
oracle4engineer
PRO
2
3.2k
iOS/Androidで同じUI体験をネ イティブで作成する際に気をつ けたい落とし穴
fumiyasac0921
1
110
VideoMamba: State Space Model for Efficient Video Understanding
chou500
0
190
個人でもIAM Identity Centerを使おう!(アクセス管理編)
ryder472
3
190
B2B SaaSから見た最近のC#/.NETの進化
sansantech
PRO
0
680
元旅行会社の情シス部員が教えるおすすめなre:Inventへの行き方 / What is the most efficient way to re:Invent
naospon
2
330
AIチャットボット開発への生成AI活用
ryomrt
0
170
EventHub Startup CTO of the year 2024 ピッチ資料
eventhub
0
110
OCI Vault 概要
oracle4engineer
PRO
0
9.7k
B2B SaaS × AI機能開発 〜テナント分離のパターン解説〜 / B2B SaaS x AI function development - Explanation of tenant separation pattern
oztick139
2
220
Featured
See All Featured
The Invisible Side of Design
smashingmag
298
50k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
RailsConf 2023
tenderlove
29
900
The Cult of Friendly URLs
andyhume
78
6k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Designing the Hi-DPI Web
ddemaree
280
34k
GitHub's CSS Performance
jonrohan
1030
460k
Transcript
WHY ELIXIR? Elixir Sofia Meetup May 2017
WHY ELIXIR? INTRO TO ELIXIR
Ventsislav Nikolov @ventsislaf
DISCLAIMER NO GIFs
None
WHAT IS ELIXIR?
• functional programming language • compiles to erlang bytecode •
immutable data • dynamically typed • concurrency, distribution, fault tolerance • hot code swapping
DATA TYPES (NOT ALL) 1_000_000 # Integer 314159.0e-5 # Float
:apple # Atom "Jon Snow" # String {:error, 404} # Tuple [1, 2, 3] # (Linked) List %{name: "Jon", age: 21} # Map
MODULES AND FUNCTIONS
ANONYMOUS FUNCTIONS add = fn(a, b) -> a + b
end add.(2, 5) # => 7
MODULES defmodule Math do def add(a, b) do a +
b end defp multiply(a, b) do a * b end end # warning: function multiply/2 is unused Math.add(2, 5) # => 7 Math.multiply(2, 5) # ** (UndefinedFunctionError) function Math.multiply/2 is undefined or private
IMMUTABILITY
colors = ["green", "apple", "red"] List.delete(colors, "apple") # => ["green",
"red"] colors # => ["green", "apple", "red"]
PATTERN MATCHING
= x = 1 # => 1 1 = x
# => 1 2 = x # ** (MatchError) no match of right hand side value: 1 x = 2 # => 2
DECOMPOSITION [x, y] = [1, 2] # x => 1,
y => 2 [1, x] = [1, 2] # x => 2 [_, x] = [1, 2] # x => 2 [head | tail] = [1, 2, 3] # head => 1, tail => [2, 3] %{name: name} = %{name: "Jon Snow", age: 21} # name => "Jon Snow"
RECURSION
def sum([]) do 0 end def sum([head | tail]) do
head + sum(tail) end
PIPE OPERATOR
Enum.sort(String.codepoints(String.downcase(word)))
lowercase = String.downcase(word) chars = String.codepoints(lowercase) ordered = Enum.sort(chars)
word |> String.downcase() |> String.codepoints() |> Enum.sort()
Elixir + Erlang = ❤
# Erlang rand:uniform(10). # Elixir :rand.uniform(10)
CONCURRENCY
PROCESSES (not OS) spawn fn -> IO.puts "Hello from another
process" end
LIGHTWEIGHT • created for couple of microseconds • 1-2 KB
initial memory footprint • up to hundreds of millions processes per VM
ISOLATION name = "Jon Snow" spawn fn -> IO.puts "Hello,
#{name}" end
MESSAGES pid = spawn fn -> receive do msg ->
IO.puts "received a message: #{msg}" end end send pid, "You know nothing, Jon Snow."
msg 1 msg 2 msg 3 mailbox
FAULT TOLERANCE
:one_for_one :one_for_all
DISTRIBUTION
None
$ iex --name one@host $ iex --name two@host $ iex
--name three@host # in node one iex> Node.connect :two@host iex> Node.connect :three@host iex> Node.list # => [:two@host, :three@host] # in node two iex> Node.list # => [:one@host, :three@host] iex> Node.spawn :three@host, fn -> IO.puts("hello") end
TOOLING
IEx (demo) $ iex iex> 2 + 5 7
MIX mix new app_name mix compile mix test mix deps.get
mix hex.publish
OBSERVER :observer.start
None
WHERE TO GO NEXT?
None
None
None
None
THANK YOU!