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
Elixir: Programação Funcional e Pragmática @ 2º...
Search
Plataformatec
August 20, 2016
Programming
2
290
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
980
O case da Plataformatec com o Elixir - Como uma empresa brasileira criou uma linguagem que é usada no mundo inteiro @ QCon SP 2018
plataformatec
1
220
Elixir @ iMasters Intercon 2016
plataformatec
1
260
GenStage and Flow by @josevalim at ElixirConf
plataformatec
17
2.7k
Elixir: Programação Funcional e Pragmática @ Encontro Locaweb 2016
plataformatec
4
280
What's ahead for Elixir: v1.2 and GenRouter
plataformatec
15
2k
Arquiteturas Comuns de Apps Rails @ RubyConf BR 2015
plataformatec
6
370
Pirâmide de testes, escrevendo testes com qualidade @ RubyConf 2015
plataformatec
10
2.3k
Dogmatismo e Desenvolvimento de Software @ Rubyconf BR 2014
plataformatec
6
850
Other Decks in Programming
See All in Programming
AWSマネコンに複数のアカウントで入れるようになりました
yuhta28
2
160
一休.com のログイン体験を支える技術 〜Web Components x Vue.js 活用事例と最適化について〜
atsumim
0
410
データの整合性を保つ非同期処理アーキテクチャパターン / Async Architecture Patterns
mokuo
46
17k
ISUCON14公式反省会LT: 社内ISUCONの話
astj
PRO
0
190
pylint custom ruleで始めるレビュー自動化
shogoujiie
0
110
Rails アプリ地図考 Flush Cut
makicamel
1
120
iOSエンジニアから始める visionOS アプリ開発
nao_randd
3
130
CI改善もDatadogとともに
taumu
0
110
苦しいTiDBへの移行を乗り越えて快適な運用を目指す
leveragestech
0
510
Unity Android XR入門
sakutama_11
0
150
Honoのおもしろいミドルウェアをみてみよう
yusukebe
1
210
Pythonでもちょっとリッチな見た目のアプリを設計してみる
ueponx
1
550
Featured
See All Featured
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
45
9.4k
Fontdeck: Realign not Redesign
paulrobertlloyd
83
5.4k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.1k
GitHub's CSS Performance
jonrohan
1030
460k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
160
15k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
49
2.3k
Building a Scalable Design System with Sketch
lauravandoore
461
33k
We Have a Design System, Now What?
morganepeng
51
7.4k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
How STYLIGHT went responsive
nonsquared
98
5.4k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Code Review Best Practice
trishagee
67
18k
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
node@srv2 node@srv1 elixir
None
None
ONDE APRENDER?.
None
None
None
None
OBRIGADO!! @plataformatec @georgeguimaraes
@elixirlang / elixir-lang.org