Slide 1

Slide 1 text

Elixir a brief intro for pythonistas

Slide 2

Slide 2 text

Disclaimer...

Slide 3

Slide 3 text

Elixir

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Elixir • General Purpose • Dynamic • Functional • "Expressive" • OTP (Erlang libraries and VM) • interoperability • ! Concurrency !

Slide 6

Slide 6 text

! 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...)

Slide 7

Slide 7 text

Show me the code

Slide 8

Slide 8 text

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 ;)

Slide 9

Slide 9 text

Other familiar things: • Similar data structures (the immutable version) • Operations, comparisons... • Docstrings • Interactive interpreter • Exception handling (kind of...) • Comprehensions • Unicode support

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

✨ New stuff

Slide 12

Slide 12 text

Pipes

Slide 13

Slide 13 text

Pipes def update_profile_from_api(url) do response |> HTTPoison.get! |> Map.get(:body) |> Poison.decode! |> parse_profile |> store end

Slide 14

Slide 14 text

Atoms # Standalone: :ok :error # Map keys responses = %{ :ok => 200 } # instead of %{ "ok" => 200 } responses = %{ ok: 200 } IO.puts(responses.ok)

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

Is python not enough?

Slide 17

Slide 17 text

well...

Slide 18

Slide 18 text

Celery fatigue • Very mature but... • ...the hammer that fixes everything • Opaque?

Slide 19

Slide 19 text

Real time? • I want to use all my cores • Sockets please • The real world is concurrent • The real world has no GIL

Slide 20

Slide 20 text

Functional Python? • Limited toolset • lambdas are not enough • second class citizen

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

Python is still great ❤ • But maybe you are curious about other tools • BONUS: You can use it with Elixir using Erlport

Slide 25

Slide 25 text

Thank you! • Questions • Read more: https://elixir-lang.org/ https://elixirschool.com/en/ Eleni Lixourioti [email protected] @geekfish_

Slide 26

Slide 26 text

Credits Icons made by - Smashicons - Flat Icons and - Freepik from www.flaticon.com, and are licensed CC 3.0 BY