When is it better to use Erlang instead of Elixir?

Are there scenarios when it’s better to use Erlang instead of Elixir? If so when and why? Thank you.

Sometimes it is simpler to express something in Erlang, at least for me. Also:

  • Erlang can be seamlessly used from Elixir, other way around isn’t always that easy. That is why I created systemd and consulate in Erlang instead of Elixir
  • creating functions with “weird names” is harder in Elixir than in Erlang, so for stuff that needs them, it is easier to write them in Erlang (ex. xmerl modules)
  • Non-macro code generation (AOT, like in Yecc and Leex) is IMHO a little bit easier in Erlang than in Elixir

Interesting question!

Could you elaborate on this? I know that the following works in Elixir:

defmodule Foo do
  name = :"is this weird enough?"
  def unquote(name)(a, b), do: a + b

and this technique is not just a ‘weird but useless trick’, it actually sees some real-life usage in places like the testing framework ExUnit, where function names are picked based on strings a user passes to the it and describe macros.


There are few cases when the “weird name” is required:

  • '$handle_undefined_function'/2
  • xmerl uses Tag(Data, Attributes, Parents, E) callbacks in Callback module, so if you have XML tag in form of <foo-bar /> then the function need to be named 'foo-bar'/4

In Erlang it is simple, because any atom can be a function name:

foo() -> ok.

'foo-bar'() -> ok.

'$foo_bar'() -> ok.

'#xml-inheritance#'() -> ok.

In Elixir you need to use unquote/1 to achieve something like that, which can look “unnatural” for many people that do not expect unquote/1 outside of quote/{1,2}.

Another thing is that in Erlang you can do:

M = foo,
F = bar,


And in Elixir you need to use apply/3, but that is a minor thing.