Elixir & Phoenix

Andrew Schutt

Functional Programming

Functional Programming

"programming paradigm treats computation as the evaluation of functions"

Functional Programming
Functional Programming

Immutable Values

  • Variables can't be changed
Functional Programming

First Class Functions 

  • Functions can be...
    • variables
    • arguments
    • returned values
    • anonymous
Functional Programming

Pure Functions

  • same input = same output
Functional Programming

Recursion

  • Recursion
    • Recursion
      • Recursion
        • Recursion
          • Recursion!

Elixir

About Elixir

  • Erlang
  • Elixir History

Erlang

About Elixir
-module(hello_module).
-export([some_fun/0, some_fun/1]).

% A "Hello world" function
some_fun() ->
  io:format('~s~n', ['Hello world!']).

% This one works only with lists
some_fun(List) when is_list(List) ->
  io:format('~s~n', List).

% Non-exported functions are private
priv() ->
  secret_info.

Erlang

About Elixir
defmodule HelloModule do
  # A "Hello world" function
  def some_fun do
    IO.puts "Hello world!"
  end

  # This one works only with lists
  def some_fun(list) when is_list(list) do
    IO.inspect list
  end

  # A private function
  defp priv do
    :secret_info
  end
end

Erlang

About Elixir
defmodule HelloModule do
  # A "Hello world" function
  def some_fun do
    IO.puts "Hello world!"
  end

  # This one works only with lists
  def some_fun(list) when is_list(list) do
    IO.inspect list
  end

  # A private function
  defp priv do
    :secret_info
  end
end

-module(hello_module).
-export([some_fun/0, some_fun/1]).

% A "Hello world" function
some_fun() ->
  io:format('~s~n', ['Hello world!']).

% This one works only with lists
some_fun(List) when is_list(List) ->
  io:format('~s~n', List).

% Non-exported functions are private
priv() ->
  secret_info.

Erlang

About Elixir

Erlang Origins

About Elixir
  • Created in 1986
  • Authored by Joe Armstrong
  • BEAM = Erlang VM

Erlang Traits

About Elixir
  • Performant
  • 99.9999999% uptime
  • Fault tolerant
  • Concurrency
  • Hot swappable

Erlang OTP

About Elixir
  • Open Telecom Protocol (OTP)
  • OTP and Erlang

Elixir History

About Elixir
  • Created in 2011
  • Authored by Jose Valim

Nerves

https://github.com/nerves-project

Nerves

  • Platform
  • Framework
  • Tooling

Lumen

https://github.com/lumen

Phoenix Framework

Phoenix Framework

  • Created in 2014
  • Authored by Chris McCord

Phoenix New

Very simple to get a new Phoenix project up and going similar to Rails

 

 

 

Running the above commands generates a simple Twitter clone.

 

 

mix phoenix.new example_app
mix ecto.create
mix phoenix.gen.html Comment comments body:string username:string
mix ecto.migrate
Phoenix Framework

LiveView

Phoenix Framework

LiveView

Phoenix Framework

Phoenix & OTP

Phoenix Framework

Phoenix & OTP

Phoenix Framework

Phoenix & OTP

Phoenix Framework

Phoenix & OTP

Phoenix Framework

Phoenix & OTP

Phoenix Framework

Thanks!

Elixir & Phoenix Lightning Talk

By Andrew Schutt

Elixir & Phoenix Lightning Talk

Slides for the introduction of an Elixir workshop for Web Geeks

  • 796