Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
Elixir: Programação Funcional e Pragmática @ 2º Tech Day Curitiba
Plataformatec
August 20, 2016
Programming
2
160
Elixir: Programação Funcional e Pragmática @ 2º Tech Day Curitiba
Plataformatec
August 20, 2016
Tweet
Share
More Decks by Plataformatec
See All by Plataformatec
O case da Plataformatec com o Elixir - Como uma empresa brasileira criou uma linguagem que é usada no mundo inteiro @ Elixir Brasil 2019
plataformatec
5
640
O case da Plataformatec com o Elixir - Como uma empresa brasileira criou uma linguagem que é usada no mundo inteiro @ QCon SP 2018
plataformatec
1
210
Elixir @ iMasters Intercon 2016
plataformatec
1
240
GenStage and Flow by @josevalim at ElixirConf
plataformatec
17
2.4k
Elixir: Programação Funcional e Pragmática @ Encontro Locaweb 2016
plataformatec
4
210
What's ahead for Elixir: v1.2 and GenRouter
plataformatec
15
1.8k
Arquiteturas Comuns de Apps Rails @ RubyConf BR 2015
plataformatec
6
350
Pirâmide de testes, escrevendo testes com qualidade @ RubyConf 2015
plataformatec
10
1.8k
Dogmatismo e Desenvolvimento de Software @ Rubyconf BR 2014
plataformatec
5
830
Other Decks in Programming
See All in Programming
T3 Stack and TypeScript ecosystem
quramy
3
760
爆速の日経電子版開発の今
shinyaigeek
2
620
ちょうぜつ改め21世紀ふつうのソフトウェア設計
tanakahisateru
7
6.4k
Functional Data Engineering - A Blueprint for adopting functional principles in data pipeline
vananth22
0
180
Enumを自動で網羅的にテストしてみた
estie
0
1.3k
Cloudflare Workersと状態管理
chimame
3
490
ECテックカンファレンス2023
kspace
1
350
Hasura の Relationship と権限管理
karszawa
0
170
子育てとEMと転職と
_atsushisakai
1
410
Unity+C#で学ぶ! メモリレイアウトとvtableのすゝめ 〜動的ポリモーフィズムを実現する仕組み〜
rossam
1
110
低レイヤーから始める GUI
fadis
18
9.4k
あなたと 「|」 したい・・・
track3jyo
PRO
2
1.1k
Featured
See All Featured
Making Projects Easy
brettharned
102
4.8k
VelocityConf: Rendering Performance Case Studies
addyosmani
317
22k
WebSockets: Embracing the real-time Web
robhawkes
58
6k
Testing 201, or: Great Expectations
jmmastey
25
5.7k
Intergalactic Javascript Robots from Outer Space
tanoku
261
26k
Producing Creativity
orderedlist
PRO
335
38k
The MySQL Ecosystem @ GitHub 2015
samlambert
240
11k
The Web Native Designer (August 2011)
paulrobertlloyd
76
2.2k
Making the Leap to Tech Lead
cromwellryan
117
7.7k
For a Future-Friendly Web
brad_frost
166
7.8k
Writing Fast Ruby
sferik
613
58k
From Idea to $5000 a Month in 5 Months
shpigford
374
44k
Transcript
@georgeguimaraes / @plataformatec ELIXIR. PROGRAMAÇÃO FUNCIONAL E PRAGMÁTICA
GEORGE GUIMARÃES
consulting and software engineering
POLÊMICAS. QUEM NUNCA?
MICROSERVIÇOS != HTTP API REST.
INTEGRAÇÃO CONTÍNUA. Provavelmente vc não faz e provavelmente não deveria
estar fazendo mesmo.
MONOREPO. Repo consistente com a organização
None
None
NOSSA GERAÇÃO TEM UM PROBLEMA. Desenvolvedores web tem que lidar
com concorrência. Não há escapatória.
CONCORRÊNCIA. Capacidade de lidar com várias coisas (ao mesmo tempo,
ou serialmente).
PARALELISMO. Capacidade de fazer várias coisas ao mesmo tempo.
CONCORRÊNCIA. Websockets, HTTP2, Alta quantidade de requests, demanda instável.
None
None
THREADS E EVENT LOOP. Modelos primitivos para lidar com concorrência.
“what makes multithreaded programming difficult is not that writing it
is hard, but that testing it is hard. It’s not the pitfalls that you can fall into; it’s the fact that you don’t necessarily know whether you’ve fallen into one of them. ”
None
— ROBERT VIRDING “Any sufficiently complicated concurrent program in another
language contains an ad hoc informally-specified bug-ridden slow implementation of half of Erlang.”
PLATAFORMA ELIXIR. Erlang and OTP, now with modern tooling.
None
30 anos
None
None
Switch
Switch
Switch
Switch
Switch Switch
Switch Browser Endpoint Server
— ELIXIR DEVELOPER “We stand in the shoulders of giants”
# #MYELIXIRSTATUS
DOCUMENTAÇÃO DE ALTO NÍVEL. Documentação ruim é bug.
None
FERRAMENTAL EMBUTIDO. Hex, Mix, ExUnit.
None
None
LINGUAGEM FUNCIONAL.
IMUTABILIDADE. “Isso muda tudo”
user = %{name: "George", interests: ["Elixir", "Ruby", "Integração Discreta"]} Suggest.to_user(user)
Analytics.save_interests(user.interests) user # => %{name: "George", interests: ["Elixir", "Ruby", "Integração Discreta"]}
NÃO TENHO LOOPS!
defmodule Fibonacci do def calc(0), do: 0 def calc(1), do:
1 def calc(n), do: calc(n-1) + calc(n-2) end Fibonacci.calc(10) # => 55
MAS, E COMO FAZER UM CONTADOR? Não é possível mudar
o conteúdo de uma variável????
defmodule Counter do def start(value) do receive do :increment ->
start(value + 1) {:get, pid} -> send(pid, value) end end end
defmodule Counter do def start(value) do receive do :increment ->
start(value + 1) {:get, caller} -> send(caller, value) end end end pid = spawn(fn -> Counter.start(10) end) send(pid, :increment) send(pid, :increment) send(pid, :increment) send(pid, {:get, self}) flush # => 13
shell
shell Counter.start(10) spawn
shell 11 increment
shell 12 increment
shell 13 increment
shell 13 :get, self 13
defmodule Counter do def start(value) do receive do :increment ->
start(value + 1) {:get, caller} -> send(caller, value) end end end pid = spawn(fn -> Counter.start(10) end) send(pid, :increment) send(pid, :increment) send(pid, :increment) send(pid, {:get, self}) flush # => 13
ACTOR MODEL. 1. Enviar mensagens para outros atores; 2. Criar
novos atores; 3. Especificar o comportamento para as próximas mensagens.
Sequential code
Sequential code elixir
Sequential code elixir
elixir
elixir
None
None
FAULT-TOLERANT. DISTRIBUTED. O objetivo não era concorrência.
Switch Switch
CONCORRÊNCIA É UM CASO DE DISTRIBUIÇÃO. Tá distribuído, mas apenas
em uma máquina.
elixir
elixir
elixir
defmodule MyApp do use Application def start(_type, _args) do import
Supervisor.Spec, warn: false children = [ supervisor(Playfair.Repo, []), worker(Playfair.Mailer, []), worker(Playfair.FileWriter, []), ] opts = [strategy: :one_for_one, name: Playfair.Supervisor] Supervisor.start_link(children, opts) end end
None
ERROS ACONTECEM. Let it crash.
ESTADO CORRUPTO PODE OCORRER. Let it crash. O processo vai
voltar com um estado limpo.
MAS SERÁ QUE FUNCIONA MESMO?
http://blog.whatsapp.com/index.php/ 2012/01/1-million-is-so-2011/ 2 million connections on a single node
Intel Xeon CPU X5675 @ 3.07GHz 24 CPU - 96GB
Using 40% of CPU and Memory
None
None
None
None
None
MICROSERVIÇOS EM UM MUNDO ELIXIR. Precisamos sempre de APIs HTTP?
elixir
[email protected]
[email protected]
elixir
None
None
ONDE APRENDER?.
None
None
None
None
OBRIGADO!! @plataformatec @georgeguimaraes
@elixirlang / elixir-lang.org