One of the biggest hurdles for a Rubyist coming to Elixir/Phoenix is the functional programming paradigm. It takes awhile to get used to and is a large mind-shift in terms of how to think about programs.

The functional paradigm is partially responsible for some of the great features of Elixir/Erlang.

The tennants of functional programming include:


Without the immutability of data, concurrency is a nightmare. There has to be some kind of guarantee for data shared between multiple processes. You get this in Elixir. Any possible value in Elixir is immutable. The only way to change the data in a variable is to rebind it completely. There is no hash.merge!(other_hash) in Elixir. (Incidentally, there aren’t hashes either.)

Avoiding “side effects”

In an object-oriented program, you define classes to model behavior and objects to hold state. You pass an object into a method, the method calls another method on the object to change some internal state that you can reference. Is this the best way? Functional programming encourages you to think simply in terms of inputs and outputs.

Some resources:


One of the first questions I had when starting with Elixir/Phoenix is if there are no objects, what do models look like?

The answer, it’s a struct!

App.Repo.get(App.User, 1)
  id: 1,
  email: ""