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 @ Encontro Locaweb 2016
Plataformatec
June 22, 2016
Technology
4
210
Elixir: Programação Funcional e Pragmática @ Encontro Locaweb 2016
Plataformatec
June 22, 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 @ 2º Tech Day Curitiba
plataformatec
2
160
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 Technology
See All in Technology
立ち止まっても、寄り道しても / even if I stop, even if I take a detour
katoaz
0
610
目指せCoverage100%! AutoScale環境におけるSavings Plans購入戦略 / JAWS-UG_SRE_Coverage
taishin
0
510
OVN-Kubernetes-Introduction-ja-2023-01-27.pdf
orimanabu
1
380
S3とCloudWatch Logsの見直しから始めるコスト削減 / Cost saving S3 and CloudWatch Logs
shonansurvivors
0
250
Pentesting Password Reset Functionality
anugrahsr
0
470
Cloudflare Workersで動くOG画像生成器
aiji42
1
490
KyvernoとRed Hat ACMを用いたマルチクラスターの一元的なポリシー制御
ry
0
170
メドレー エンジニア採用資料/ Medley Engineer Guide
medley
3
5.1k
Kaggleシミュレーションコンペの動向
nagiss
0
270
Hatena Engineer Seminar #23 「チームとプロダクトを育てる Mackerel 開発合宿」
arthur1
0
510
初めてのデータ移行プロジェクトから得た学び
tjmtmmnk
0
340
Oracle Cloud Infrastructure:2023年1月度サービス・アップデート
oracle4engineer
PRO
0
160
Featured
See All Featured
Making the Leap to Tech Lead
cromwellryan
117
7.7k
No one is an island. Learnings from fostering a developers community.
thoeni
12
1.5k
The Illustrated Children's Guide to Kubernetes
chrisshort
22
43k
Building Better People: How to give real-time feedback that sticks.
wjessup
346
17k
4 Signs Your Business is Dying
shpigford
171
20k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
182
15k
Bootstrapping a Software Product
garrettdimon
299
110k
How to Ace a Technical Interview
jacobian
270
21k
Making Projects Easy
brettharned
102
4.8k
Fashionably flexible responsive web design (full day workshop)
malarkey
396
63k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
217
21k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
239
19k
Transcript
@georgeguimaraes / @plataformatec ELIXIR. PROGRAMAÇÃO FUNCIONAL E PRAGMÁTICA
consulting and software engineering
None
None
ESTAMOS CONTRATANDO! http://plataformatec.workable.com
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”
list = [1, 2, 3] DoSomethingWith(list) list = [4, 5,
6] AnotherThingWith(list)
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
defmodule MyApp.Mixfile do use Mix.Project def application do [mod: {Playfair,
[]}, applications: [:phoenix, :phoenix_html, :cowboy, :logger, :gettext, :phoenix_ecto, :postgrex, :calendar]] end defp deps do [ {:phoenix, "~> 1.1.4"}, {:postgrex, ">= 0.0.0"}, {:phoenix_ecto, "~> 2.0"}, {:phoenix_html, "~> 2.4"}, {:phoenix_live_reload, "~> 1.0", only: :dev}, {:gettext, "~> 0.10"}, {:cowboy, "~> 1.0"}, {:credo, "~> 0.3", only: [:dev, :test]}, {:basic_auth, "~> 1.0"}, {:csv, "~> 1.2.4"}, {:scrivener, "~> 1.0"}, {:scrivener_html, "~> 1.0"}, {:calendar, "~> 0.13"} ] end end
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
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
None
consulting and software engineering
DÚVIDAS? @plataformatec @georgeguimaraes
@elixirlang / elixir-lang.org