At Monterail we have fancied the Elixir language for quite a long time. However, for some reasons, we failed to get it into production usage except for a few minor implementations. And I felt like this should change. So when Plataformatec shared the idea on how to learn the language together in teams, within a company, we didn’t hesitate long. In simplest terms—you go through the book for beginners called Learn Functional Programming with Elixir, dedicate each week to the next chapter and do exercises listed at the end of each chapter. Doesn’t it sound like an awesome initiative?

I want to share the reasons why I think you should learn Elixir in 2020. Let’s start with why we got interested in Elixir many years ago.

So we started learning Elixir Phoenix during regular meetings every Friday evening. And then Advent came, also to the coding life and we expanded Elixir education onto participating in the Advent of Code with the language creator, José Valim. AoC is a series of small programming puzzles for a variety of skill sets and skill levels in any programming language you like. It allowed us to learn A LOT in such a short time—it was challenging, exhausting but most above all, really fun!

And as a result of our effort, we managed to introduce Elixir to a key part of our client’s application.

We learned our lessons so I decided to share with you some of my findings, i.e. patterns, specific functions or quirks. A very experienced Elixir developer probably won’t catch much new here but if you are new in the alchemists’ community, you’re more than likely to benefit from it.

Scripting with Elixir — a short tutorial

When you come from the world similar to Ruby, you might have an issue at the beginning with organizing a workflow when you just want to script a small thing. How to test the script with Elixir? Do I need a full mix application? Do I have to recompile the code after every change? Luckily, there is a way:

defmodule Example do
  def fun(bar, baz) do
    ...
  end
end

case System.argv() do
  ["--test"] ->
    ExUnit.start()

    defmodule ExampleTest do
      use ExUnit.Case

      import Example

      test "my code" do
        assert fun() == 1
      end
    end

  [arg1, arg2] ->
    Example.fun(arg1, arg2) |> IO.puts()
end

Simplecase on System.argv() allows you to create a script with tests as simple to run as typing elixir script.exs --test.

And when talking about testing, I cannot keep myself from mentioning Doctest—it’s so cool that it should be banned.

#elixir #development #programming

Why Learn Elixir in 2020? — Elixir Tutorial for Beginners
1.70 GEEK