Why I chose Elixir to learn this year (and initial impressions)

Because I liked the color. Just kidding - but I didn't invest too much time into making the choice - though I'm sure that all the things I read or heard during this past year influenced me.

It quickly boiled down to Go or Elixir

Elixir won because:

  • Prag Dave recommends it
  • I wanted to finally follow through on a functional language ( I've played with Scala and F# before, but somehow I didn't fall in love)
  • For one reason or another I never got excited about Ruby, but people keep telling me how nice its syntax is, and Elixir's is inspired by Ruby's, so I should get a taste. And semicolons are not required!
  • it's running on the Erlang VM, which seems to be quite different from the things I've used in the past

First impressions

So far, I haven't yet finished the second page of the tutorial, have solved the first few Euler problems, subscribed to the elixir-talk mailing list, and have asked for help on the IRC channel. So I'm quite at the beginning.

Some of the things that were a "culture shock" or at least unexpected/confusing for me were:

  • To quit the REPL (iex), one has to do CTRL-C. Not CTRL-D, or type exit. Since at first I didn't read the startup message, I had the "get me out of here" desperation first time Vim users are famous for.
  • Different types require different pattern matching - {head | tail } = {1, 2, 3} does not work, it only works on lists [head | tail ] = [1, 2, 3].
  • Operators that should be the same are not. For concatenating strings, you use <>, but for joining two lists, you use ++. My python roots rebel - even if this likely provides helpful type hints once I'm familiar with it
  • Strong (and, or, and not) and weak (&&, ||, and !) boolean comparisons. I'm quite afraid of the mistakes I'll do, not realizing whether I check for strict boolean values or just against nil/false. Scary...
  • Unlike in Python, the REPL (iex) and the script executor (elixir) are two separate commands.
  • There are no semicolons alright, but there are too many ends required for my taste. Python did spoil me in this aspect...
  • Blocks need to be parenthesized properly otherwise some nasty surprises happen, e.g.: is_number if true do 1 + 2 end is parsed as is_number(if true) do 1 + 2 end
  • Pattern matching is powerful on one hand, but quite limited in others. Probably once I understand how it works, I won't try to do things like
    a = 1
    (^a + 1) = 2
    as match. Though I'm still curious why ^a = (2 - 1) works
  • Guard clauses - probably the list of what you can and cannot do is due to some Erlang VM internals, but I dislike memorizing things...
  • Maybe it's too early for me to read release notes - reading "The list [1, 2, three: :four] now correctly expands to [1, 2, {:three, :four}]" makes me feel again that I have to be super careful when reading code...

But there are really nice and fun moments, such as:

  • The installation was easy - thanks to Avdi Grim's post.
  • I was able to quickly understand the structure of the exceptions - the <function name>/<N> refers to the number of arguments of the function.
  • Nice utf support - though since all strings are bytes, I have to keep this in mind for pattern matching - <<f, rest :: binary>> matches differently from <<f :: utf8, rest :: binary >>. So maybe this belongs to the above list :)
  • I love how anonymous functions can be turned into full blocks, unlike in Python.
  • fib = Stream.unfold({0, 1}, fn {a, b} -> {a, {b, a + b}} end)
  • #elixirlang on freenode is great and super helpful

In summary

"It's your foot". But I'll keep with learning the language, for I know a ton of people who can't imagine writing maintainable programs without static type checking, yet I know it's possible. Back in the days of Alt.NET, the motto was that we are adults, so we can use knives and scissors...

What do you think? I would love if you would leave a comment - drop me an email at hello@zsoldosp.eu, tell me on Twitter!

Posted on in elixir, programming languages, software by

Share this post if you liked it - on Digg, Facebook, Google+, reddit, or Twitter

Your email address