by rdtsc · 2y ago · 0 comments
Other factors: Erlang/OTP base libraries are written in Erlang, so it feels like there is less friction when using them. With a lot of recent language improvements in Erlang like maps, better command line completion, sigils, etc., I feel like I am not missing too much from Elixir's ergonomics.
One caveat might be if I had do a web app, then Phoenix just has a lot of goodies that are nice to have, and maybe then only then I might consider Elixir.
And not make it sound like I am berating Elixir, and to balance things out, I'd like to say the Elixir community is amazing and the collaboration and improvement they've brought to Erlang/OTP are significant in the recent years. It's nice to collaborate and be part one one large BEAM VM community.
Just to clarify in case anyone gets the wrong idea about Elixir—Elixir data is immutable (you can't modify structures, only make new ones) and variables cannot be reassigned, but Elixir does allow shadowing variable names.
The difference between shadowing and reassignment is significant, because it means that this code outputs "10", not "20":
x = 10
closure = fn () -> x end
x = 20
IO.puts closure.()
# 10
Contrast that with the otherwise equivalent JavaScript: let x = 10;
const closure = () => x;
x = 20
console.log(closure())
// 20
Shadowing allows you the convenience of reusing names without the risk of a variable changing out from under you via spooky action at a distance.So it's immutable variables vs immutable data. Both Erlang and Elixir have immutable data. That's the stuff variables refer to. But in Erlang the variables are also immutable, so X = X + 1, just like in basic math, doesn't make sense.
https://dashbit.co/blog/comparing-elixir-and-erlang-variable...
iex(1)> x = 4
4
iex(2)> ^x = 3
** (MatchError) no match of right hand side value: 3 foo = "Hello"
if true do
foo = "Bye!"
end
foo # `foo` is still "Hello" here
I guess if you have REALLY long functions it could be ¯\_(ツ)_/¯