BT

Your opinion matters! Please fill in the InfoQ Survey!

Elixir 1.3 Brings New Language Features, APIs, and Improved Tooling

| by Sergio De Simone Follow 6 Followers on Jun 27, 2016. Estimated reading time: 2 minutes |

A note to our readers: As per your request we have developed a set of features that allow you to reduce the noise, while not losing sight of anything that is important. Get email and web notifications by choosing the topics you are interested in.

Elixir 1.3, recently announced by José Valim, deprecates imperative assignments and adds new types and accessors, improves its Mix build tool and the ExUnit unit testing framework.

Elixir 1.3 deprecates imperative assignments to variables that are accessed in an outer scope and will emit a warning each time it finds one such use. The rationale behind this is that assigning to a variable that is used in an outer scope amounts to adding an implicit return value to the inner scope. Take for example, the following function definition:

def format(message, opts) do
  path =
    if (file = opts[:file]) && (line = opts[:line]) do
      relative = Path.relative_to_cwd(file)
      message  = Exception.format_file_line(relative, line) <> " " <> message
      relative
    end

  {path, message}
end

The if block, besides returning a value for path, is also changing the value in message, which is then returned along with path from the enclosing function. This is considered bad usage in Elixir 1.3 and should be refactored into the following code, which makes it explicit that the if block returns two values:

def format(message, opts) do
  path =
    if (file = opts[:file]) && (line = opts[:line]) do
      relative = Path.relative_to_cwd(file)
      message  = Exception.format_file_line(relative, line) <> " " <> message
      {relative, message}
    end

  {path, message}
end

Another language feature meant to make it simpler to traverse nested data structures, is new access selectors. The following snippet show how you can traverse a map containing an embedding map associated to the languages key, and convert all of its elements for the name key to uppercase:

iex> update_in myMap, [:languages, Access.all(), :name], &String.upcase/1

Elixir’s build tool, Mix, is now able to do cross reference checking, which is useful, for example, in detecting calls to not existing modules and functions, or finding all places that calls a function belonging to a given module, or generating a dependency graph. Additionally, Mix streamlined its output, thus making it easier to spot warnings. Another improvement to Mix in Elixir 1.3 is better dependency tracking, which translates into faster compile times.

ExUnit, Elixir’s unit testing framework, leverages Mix cross-ref checks to add a new flag, --stale which ensures that only unit tests that may have changed since the last run are executed. Other improvements in ExUnit include better assertion output and improved test organization using named blocks.

There are many more changes in Elixir 1.3. You can read the full list in the release notes.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT