Do you want to pick up from where you left of?
Take me there
Elixir School
Presents

A look at Elixir 1.6

By Sean Callan | Posted 2018-04-02

Follow along as we take a peek at what’s inside the latest Elixir release. Learn more about the all new code formatter, exciting dynamic supervisors, and changes coming to your code editors that make working in Elixir even better!

January 17th was like any other day until something exciting happened: José gave Elixir 1.6 to the people. Much like the versions before it this one continues the trend of feature packed releases made possible by the collaborative efforts of many.

Let’s take a look together at the exciting features made it into the 1.6 release and how they play into our applications.

Code Formatter

While some may not think a code formatter is essential there’s one thing that the new mix format task makes sure of: gone are debates and arguments about which styleguide or format is the “right” one.

It’s easy to apply the formatter to your project if you’re using 1.6:

mix format lib/**/*.ex

Newly generated projects will include the .formatter.exs configuration file that allows you to fine tune how the formatter it applied to your code.

Together the community was able to apply the formatter to the entire Elixir code base. If you’re interested in seeing all the changes made head over to Elixir Issue #6643.

If you’re not looking to dig through commits don’t worry, we’ve got you covered. Let’s take a quick look at just a handful of the changes made to the core project with the formatter:

  • Add paranthesis to function calls:

    Before

    file = Keyword.get opts, :file, "nofile"
    line = Keyword.get opts, :line, 1

    After

    file = Keyword.get(opts, :file, "nofile")
    line = Keyword.get(opts, :line, 1)
  • Realign and reorganize complex statements:

    Before

    valid = is_list(aliases) and Enum.all?(aliases, fn {k, v} ->
     is_atom(k) and is_atom(v)
    end)

    After

    valid =
      is_list(aliases) and
        Enum.all?(aliases, fn {k, v} ->
          is_atom(k) and is_atom(v)
        end)

DynamicSupervisor

Easily one of the most exciting features of 1.6, the Dynamic Supervisor provides a powerful new tool to Elixir developers.

With traditional Supervisors we are expected to provide a static list of child processes at initialization. While this works for many situations it requires us to know the exact number of supervised processes we need at start-up which may not always be foreseeable.

Door opens and in strolls a new kid in town: DynamicSupervisor.

Those constraints are a thing of the past with our new friend the DynamicSupervisor. Unlike other supervisors, the dynamic supervisor starts with no children. Instead we add those child processes as necessary using the start_child/2 function.

Look for an all new DynamicSupervisor lesson soon!

Compiler Behaviour

The new Mix.Task.Compiler behaviour won’t be immediately noticeable or useful to most end users but it’s exciting nonetheless.

Through this change Elixir is able to ensure all compilers conform to a specification and provide adequate diagnostics in the event of errors. This improved diagnostics makes integration with code editors easier. The end result is better tooling support for Elixir users.

If you’re interested in taking a closer look at these changes we recommend you check out what Jake Becker, one of the features contributors, has to say in his blog post ElixirLS 0.2: Better builds, code formatter, and incremental Dialyzer.

While at first glance it may not seem like much, these are just a few key features that make up the 1.6 release. Dozens of fixes, tweaks, and other improvements make this release the best yet.

A huge thank you to those who contributed to this release, you’re doing a spectacular job!

We want to hear from you! Are you using any of these features yet? What are your favorite changes in 1.6?

Until next time!