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 - a brief intro for pythonistas
Search
Eleni Lixourioti
March 25, 2019
Programming
0
46
Elixir - a brief intro for pythonistas
Lightning talk given at Python DBBUG.
Credit on last slide.
Eleni Lixourioti
March 25, 2019
Tweet
Share
More Decks by Eleni Lixourioti
See All by Eleni Lixourioti
GDPR + Django Model Collector
geekfish
0
170
Intro to Python
geekfish
0
81
Other Decks in Programming
See All in Programming
Tuning GraphQL on Rails
pyama86
2
1.2k
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
340
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
590
cXML という電子商取引の トランザクションを支える プロトコルと向きあっている話
phigasui
3
2.3k
Dev ContainersとGitHub Codespacesの素敵な関係
ymd65536
1
140
OpenTelemetryでRailsのパフォーマンス分析を始めてみよう(KoR2024)
ymtdzzz
5
2k
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
6
7.3k
From Subtype Polymorphism To Typeclass-based Ad hoc Polymorphism- An Example
philipschwarz
PRO
0
200
CSC509 Lecture 11
javiergs
PRO
0
180
Jakarta EE meets AI
ivargrimstad
0
260
RailsのPull requestsのレビューの時に私が考えていること
yahonda
5
2.9k
Click-free releases & the making of a CLI app
oheyadam
2
110
Featured
See All Featured
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
How to Think Like a Performance Engineer
csswizardry
20
1.1k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
Six Lessons from altMBA
skipperchong
27
3.5k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
370
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
Speed Design
sergeychernyshev
24
600
How GitHub (no longer) Works
holman
310
140k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Transcript
Elixir a brief intro for pythonistas
Disclaimer...
Elixir
None
Elixir • General Purpose • Dynamic • Functional • "Expressive"
• OTP (Erlang libraries and VM) • interoperability • ! Concurrency !
! Concurrency • EVM processes (not OS processes) • Like
super tiny threads... • ...but no shared state! • Easy to spawn • Actor Model • Supervisors (it's processes all the way down...)
Show me the code
Python def hello(name): print(f"Hello, {name}") Elixir defmodule MyApp.Greetings do def
hello(name) do IO.puts("Hello, #{name}") end end hello("Linda") # Both hello "Linda" # Elixir only ;)
Other familiar things: • Similar data structures (the immutable version)
• Operations, comparisons... • Docstrings • Interactive interpreter • Exception handling (kind of...) • Comprehensions • Unicode support
def update_profile_from_api(url): response = requests.get(url) raw_profile = response.json() profile =
parse_profile(raw_profile) return store(profile) vs def update_profile_from_api(url) do response = HTTPoison.get!(url) raw_profile = Poison.decode!(response.body) profile = parse_profile(raw_profile) store(profile) end
✨ New stuff
Pipes
Pipes def update_profile_from_api(url) do response |> HTTPoison.get! |> Map.get(:body) |>
Poison.decode! |> parse_profile |> store end
Atoms # Standalone: :ok :error # Map keys responses =
%{ :ok => 200 } # instead of %{ "ok" => 200 } responses = %{ ok: 200 } IO.puts(responses.ok)
Many more shiny things • Processes as a core feature
• Macros (make your own DSLs!) • Increasingly evolving package ecosystem (Phoenix, Ecto, Nerves...) • Erlang's mature, battle tested, ecosystem
Is python not enough?
well...
Celery fatigue • Very mature but... • ...the hammer that
fixes everything • Opaque?
Real time? • I want to use all my cores
• Sockets please • The real world is concurrent • The real world has no GIL
Functional Python? • Limited toolset • lambdas are not enough
• second class citizen
Second class citizen? Preventing mutation... def update_a_thing(thing): new_thing = thing.copy()
new_thing.update("foo": "should I use deepcopy instead?") return new_thing
Impromptu pattern-matching-single-dispatch- thing... def render(response): return { 200: _render_succesful, 400:
_render_bad_request, 403: _render_forbidden, 404: _render_not_found, }[response.status](response) def _render_successful(response): return "OK" def _render_bad_request(response): return "Such and such things are wrong: " + response.errors
Elixir def render(%{status: 200}) do "OK" end def render(%{status: 400}
= response) do "Such and such things are wrong: " <> response.error_msg end def render(%{status: 403}) do "The FBI has been dispatched" end def render(%{status: 404}) do "Not Found" end
Python is still great ❤ • But maybe you are
curious about other tools • BONUS: You can use it with Elixir using Erlport
Thank you! • Questions • Read more: https://elixir-lang.org/ https://elixirschool.com/en/ Eleni
Lixourioti
[email protected]
@geekfish_
Credits Icons made by - Smashicons - Flat Icons and
- Freepik from www.flaticon.com, and are licensed CC 3.0 BY