I really like what the BEAM brings to the table in the sense of safety and concurrency. Because I have worked with Ruby before I though that Elixir would be the answer and in some ways it was. The thing is that I found Elixir to be too big and opinionated. Is Erlang simpler than Elixir? And the big question is, from Erlang can I use the nice libraries that are available at Elixir?
Hello! Welcome to the forum.
Erlang is quite a lot simpler than Elixir in my opinion.
Sort of. Youâll have to install Elixir on your system and also configure your build tool with a plugin or such so that it knows how to compile the Elixir code.
If the library is heavily macro based (like Phoenix, Ecto, NimbleParsec etc) you wonât be able to use them outside of Elixir.
Hello! Welcome to the forum.
Thanks
If the library is heavily macro based (like Phoenix, Ecto, NimbleParsec etc) you wonât be able to use them outside of Elixir.
Ok, this makes things more complicated, not impossible for sure, but more complicated as I would write most of the code in Erlang and then I would have to write some Glue code to connect Erlang with Elixir.
Hiya. Honestly, even if thereâs no heavy macro usage, in my experience itâs still not straightforward to use Elixir libs from erlang. (Others may disagree, YMMV, etc.)
Thereâs some basic hygiene stuff thatâs simple but still quite noisy: you have to namespace everything as atoms in a very erlang-unnatural way (e.g. 'Elixir.Lib.Module':function()
), and add metadata to maps to make them compatible commonplace Elixir struct
s (e.g. #{ '__struct__' => 'Elixir.Lib.StructName', k => V [...] }
). Naturally you also need to have the whole Elixir toolchain installed everywhere you want to use it.
Obviously none of that is a huge deal, but neither is it the main issue, which unfortunately is IME more fundamental in terms of build and run: in short, it does work, you can do it, but the toolchain integration isnât really there yet. Itâs not totally clear which rebar plugin to use where, and it never really works straightforwardly in the way rebar3
âjust worksâ for Erlang-only projects, or mix
âjust worksâ for an Elixir project. Thereâs always some slight mismatch between building in dev vs release, mac vs linux, local vs inside docker, getting mix
set up in CI, whatever. Itâs never anything totally consistent and someone else always got it working somewhere else, so youâll always get someone saying âoh it must be your setupâ - but really, itâs not, itâs just that Elixir wasnât designed from the ground up to be interoperable with Erlang, only the other way round, and such interop that there is is kind of worked-around or retro-fitted, so itâs never going to âjust workâ reliably everywhere.
It kind of works, and gets you tantalisingly close to being able to just pull in some neat piece of Elixir code, but in the 5 or 6 times over the last few years when Iâve tried again to see if it worked any better than previously because I wanted to use some cool Elixir library, every single time Iâve ended up giving up and either finding an erlang equivalent, or just writing my own version.
So for now, even ignoring ecto/phoenix etc (let alone wildly cool stuff like scenic that Iâd love to use), I just assume itâs a no-go, and stick to straight erlang. Perfect example: the other day I wanted to do something TUI-ish and found ex_termbox which seems super handy and nicely put together, and I got it running, but using it in anger involved unwieldy #{'__struct__'}
/cell mappings everywhere so that using it from erlang just feels clumsy and coding it takes longer than it should, so I ended up spending a day porting it to erlang. Itâs probably more my obsessive tidiness than actual time efficiency dictating I should do that, but it feels a whole lot neater, and - more importantly - I now know I wonât ever have to mess around with mix and the problems likely associated with it, especially when working cross-platform.
As much as I prefer and plan to stick with erlang, if your two main motivations are BEAM and Elixir libraries, you might be better off biting the bullet and going with Elixir. Personally Iâd say itâs worth using erlang without worrying too much about Elixir because itâs smaller, simpler, and everything around OTP etc were designed for it and thereâs none of the impedance mismatch that comes along with any kind of language interop. (Maybe gleam makes it much smoother, I havenât dug deep into it.) On the flip side, if you really donât like Elixirâs size and opinions but canât do without some of its libraries, then even if it is fiddly, you can probably get it working for your scenario.
Best of luck either way
Build tools are a big pain point. Mix âjust worksâ with both Elixir and Erlang, so if I need both in one project I tend to use Mix.
Same goes for Gleam, if I need Gleam and Mix in a project Iâll use Mix with a plugin that support Gleam. It has been quite challenging to get Elixir packages compiling outside of a Mix project.