This talk I gave at the 2017 madewithlove retreat (https://2017.mwl.be/) and also at the Maceió DEV Meetup #21 (https://www.meetup.com/pt-BR/maceio-dev-meetup/events/245530346/)
The idea is to compare building the same application in two web frameworks in different languages. One I know and work daily, which is Laravel, and the other one is new to me and I had no experience in Elixir, the language the framework was built in.
The idea is not to compare both languages or frameworks. My goal was mainly learn something new building the same thing twice and see how different languages and frameworks can be used to build similar things.
---
## Slides links
Slide 13:
- https://www.youtube.com/watch?v=7Zlp9rKHGD4
Slide 18:
- https://www.youtube.com/watch?v=aA-XHI-EYcM
Slide 20:
- https://github.com/tonysm/slackish-laravel
- https://github.com/tonysm/slackish-phoenix
Slide 32:
- http://phoenixframework.org/blog/the-road-to-2-million-websocket-connections
Slide 38:
- https://www.youtube.com/watch?v=H686MDn4Lo8
---
## References for this talk
Functional Programming; What? Why? When? (Robert C Martin) https://www.youtube.com/watch?v=7Zlp9rKHGD4
Real World Elixir Deployment (Pete Gamache) https://www.youtube.com/watch?v=H686MDn4Lo8
Erlang: The Movie https://www.youtube.com/watch?v=xrIjfIjssLE
Lonestar ElixirConf 2017- KEYNOTE: Phoenix 1.3 by Chris McCord https://www.youtube.com/watch?v=tMO28ar0lW8
GOTO 2016 • Phoenix a Web Framework for the New Web • José Valim https://www.youtube.com/watch?v=bk3icU8iIto
ElixirConf 2016 - Giving up the Object-Oriented Ghost by Morgan Lanco https://www.youtube.com/watch?v=_VpZ6gQsyDY
GOTO 2017 • Elixir: The only Sane Choice in an Insane World • Brian Cardarella https://www.youtube.com/watch?v=gom6nEvtl3U
Elixir, quem é esse pokemon? - Bruno Volcov https://www.youtube.com/watch?v=aA-XHI-EYcM
Ecto, você sabe o que é? - Amanda Sposito https://www.youtube.com/watch?v=hQM4VdEpz6g
Programming Phoenix (book) by Chris McCord, Bruce Tate, and José Valim https://pragprog.com/book/phoenix/programming-phoenix
12. What is a function?
● In math, functions are all about transforming input to output (sounds familiar?)
● You might be used to expressing functions in math like so:
y = x * 2 or g = x ^ 2
● But there is another notation that is much more expressive (IMO):
f(x) = x * 2
f(5) = 5 * 2
f(5) = 10
13. f(x) = x * 2
---
const f = (x) => x * 2
var x = 5
assertEquals(f(x), 10)
assertEquals(f(x), f(x))
source
14. class Value {
constructor(val) {
this.value = val;
}
}
const f = (x) => x.value++ * 2
const x = new Value(5);
console.log(f(x) == f(x)); // True or False?
console.log(x.value); // What is the value?
15. class Value {
constructor(val) {
this.value = val;
}
}
const f = (x) => x.value++ * 2
const x = new Value(5);
console.log(f(x) == f(x)); // false
console.log(x.value); // 7
22. defmodule SlackishphxWeb.CompanyController do
use SlackishphxWeb, :controller
plug SlackishphxWeb.Plugs.RequireAuth
def create(conn, %{"company" => params}) do
case Slackishphx.Auth.create_company(conn.assigns[:user], params) do
{:ok, company} ->
conn
|> create_default_channel(company)
|> switch_company(conn.assigns[:user], company)
{:error, changeset} ->
conn
|> render("new.html", changeset: changeset)
end
end
end
23. defmodule SlackishphxWeb.CompanyController do
use SlackishphxWeb, :controller
plug SlackishphxWeb.Plugs.RequireAuth
def create(conn, %{"company" => params}) do
case Slackishphx.Auth.create_company(conn.assigns[:user], params) do
{:ok, company} ->
conn
|> create_default_channel(company)
|> switch_company(conn.assigns[:user], company)
{:error, changeset} ->
conn
|> render("new.html", changeset: changeset)
end
end
end
24. defmodule SlackishphxWeb.CompanyController do
use SlackishphxWeb, :controller
plug SlackishphxWeb.Plugs.RequireAuth
def create(conn, %{"company" => params}) do
case Slackishphx.Auth.create_company(conn.assigns[:user], params) do
{:ok, company} ->
conn
|> create_default_channel(company)
|> switch_company(conn.assigns[:user], company)
{:error, changeset} ->
conn
|> render("new.html", changeset: changeset)
end
end
end
34. defmodule Slackishphx.Auth.User do
use Ecto.Schema
# ...
schema "users" do
field :name, :string
field :email, :string
field :google_id, :string
field :google_token, :string
field :avatar_path, :string
belongs_to :current_company, Company
has_many :companies, Company, foreign_key: :owner_id
timestamps()
end
end
35. defmodule Slackishphx.Auth.User do
# ...
@doc false
def register_from_google_changeset(%User{} = user, attrs) do
user
|> cast(attrs, [:name, :email, :google_id, ...])
|> validate_required([:name, :email, ...])
end
end
36. defmodule Slackishphx.Auth do
@moduledoc """
The Auth context.
"""
def create_company(%User{} = user, params) do
changeset = user
|> build_assoc(:companies)
|> Company.create_company_changeset(params)
Repo.insert(changeset)
end
end
44. References
● Functional Programming; What? Why? When? (Robert C Martin)
https://www.youtube.com/watch?v=7Zlp9rKHGD4
● Real World Elixir Deployment (Pete Gamache)
https://www.youtube.com/watch?v=H686MDn4Lo8
● Erlang: The Movie https://www.youtube.com/watch?v=xrIjfIjssLE
● Lonestar ElixirConf 2017- KEYNOTE: Phoenix 1.3 by Chris McCord
https://www.youtube.com/watch?v=tMO28ar0lW8
● GOTO 2016 • Phoenix a Web Framework for the New Web • José Valim
https://www.youtube.com/watch?v=bk3icU8iIto
45. References
● ElixirConf 2016 - Giving up the Object-Oriented Ghost by Morgan Lanco
https://www.youtube.com/watch?v=_VpZ6gQsyDY
● GOTO 2017 • Elixir: The only Sane Choice in an Insane World • Brian Cardarella
https://www.youtube.com/watch?v=gom6nEvtl3U
● Elixir, quem é esse pokemon? - Bruno Volcov
https://www.youtube.com/watch?v=aA-XHI-EYcM
● Ecto, você sabe o que é? - Amanda Sposito
https://www.youtube.com/watch?v=hQM4VdEpz6g
● Programming Phoenix (book) by Chris McCord, Bruce Tate, and José Valim
https://pragprog.com/book/phoenix/programming-phoenix