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
consulatein 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.
- Non-macro code generation (AOT, like in Yecc and Leex) is IMHO a little bit easier in Erlang than in Elixir
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 end
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
There are few cases when the “weird name” is required:
Tag(Data, Attributes, Parents, E)callbacks in
Callbackmodule, so if you have XML tag in form of
<foo-bar />then the function need to be named
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
Another thing is that in Erlang you can do:
M = foo, F = bar, M:F().
And in Elixir you need to use
apply/3, but that is a minor thing.