Web framework developed with Elixir
Elixir
Erlang Virtual Machine (a.k.a. BEAM), anologous to JVM.
defmodule HelloWorld do
def greeting(name \\ "World") do
"Hello, #{name}!"
end
end
IO.puts
elixir hello.exs
Actor model of concurrency
Asynchronous (lightweight) processes sending immutable messages to each other.
Immutable data
s = "HELLO"
String.downcase s
IO.puts s # => "HELLO"
s = String.downcase s
IO.puts s # => "hello"
Pipeline operator
Sanitizer.sanitize(html)
|> Markdownify.render
|> MarkdownSanitizer.sanitize
|> Formatter.format
|> String.gsub "'", "'"
Pattern matching
Multiple methods with the same name, chosen based on best match for given arguments.
Recursion rather than looping
Phoenix
Developed symbiotically with Elixir.
Precompiled templates
View modules
Views and templates are not the same.
defmodule MyApp.UserView do
use MyApp.Web, :view
alias MyApp.User
def first_name(%User{name: name}) do
end
end
Ecto for accessing data stores
Not bundled with Phoenix, but common developers.
defmodule MyApp.Category do
use MyApp.Web, :model
schema "categories" do
field :name, :string
timestamps
end
@required_fields ~w(name)
@optional_fields ~w()
def changeset(struct, params \\ %{}) do
struct
|> cast(params, [:name])
|> validate_required([:name])
end
def alphabetical(query) do
from c in query, order_by: c.name
end
end