[フレーム]
BT

InfoQ Software Architects' Newsletter

A monthly overview of things you need to know as an architect or aspiring architect.

View an example

We protect your privacy.

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Unlock the full InfoQ experience

Unlock the full InfoQ experience by logging in! Stay updated with your favorite authors and topics, engage with content, and download exclusive resources.

Log In
or

Don't have an InfoQ account?

Register
  • Stay updated on topics and peers that matter to youReceive instant alerts on the latest insights and trends.
  • Quickly access free resources for continuous learningMinibooks, videos with transcripts, and training materials.
  • Save articles and read at anytimeBookmark articles to read whenever youre ready.

Topics

Choose your language

InfoQ Homepage News Elixir 1.3 Brings New Language Features, APIs, and Improved Tooling

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

Jun 27, 2016 2 min read

Write for InfoQ

Feed your curiosity. Help 550k+ global
senior developers
each month stay ahead.
Get in touch

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
Style

This content is in the Availability topic

Related Topics:

Related Content

The InfoQ Newsletter

A round-up of last week’s content on InfoQ sent out every Tuesday. Join a community of over 250,000 senior developers. View an example

We protect your privacy.

BT

AltStyle によって変換されたページ (->オリジナル) /