Three Things I’m Liking about Phoenix

Tom Kruijsen
Nov 6, 2015 · 3 min read

A colleague recently got me excited about Elixir and the Phoenix web framework. Now I’m not building telephone networks anytime soon, but I’m always intrigued by a new web framework to see on which fronts they’re pushing the envelope. I’ve worked a lot with Rails over the past few years and did some Django before that. I may even have touched a Java web app a long time ago, but that is best talked about in whispers. Phoenix is a great chance to explore what a web framework is today.

1. Changesets

@required_fields ~w(title author release_date isbn)
@optional_fields ~w(description)def create(model, params \\ :empty) do
 |> cast(params, @required_fields, @optional_fields)
 |> slugify_field(:title, :slug)

The create function here returns a changeset. The cool thing is that we do not validate the model, we validate the changeset instead. This allows us to check for required fields and whitelist other fields right where it matters. And something like creating a slug, which we might only want to do on create, can be added to this changeset. The changeset for updating might be completely different.

The advantage of this is that we’re not modifying the model we have before we have checked the changes. Of course immutability is a big thing in Elixir, so doing that wouldn’t even make sense. But this might be a good idea in other languages as well. You could view the changes you’re making to a model as a completely separate entity and process, before giving it to the database to actually change your data.


Phoenix has separated Views from Templates. Templates are html documents with some code in them. Views are modules which are responsible for rendering the Template. That makes it an awesome place for view-logic. Rails provides helpers for this, which ended up somewhere globally, and that’s a stink if there ever was one.

Views in Phoenix mean you can write Elixir functions that you can cleanly call from your template. This keeps your template clean from code and other templates don’t need to worry about helpers that magically appear there.

3. JavaScript asset pipeline

I have to admit I wasn’t familiar with Brunch to begin with, but it seems to work fine. It builds modern JavaScript out of the box and allows me to use CSS preprocessors. I really like that Phoenix focusses on what it does best: be an Elixir web framework. But I also really like that there are modern tools for static assets available out of the box. Having cake? Eating cake? Both? Count me in!

The server-side web framework gets little time in the spotlight with all the front-end frameworks flying around these days. But it’s good to see that there’s still innovation happening. Not all good ideas have already been found and there’s improvement happening every day. And I haven’t even touched on all of the other cool things Phoenix is doing. It’s still an awesome time to work on the server side of things.

Tom Kruijsen

Written by

I'm Tom. I write software and stuff.