Hacker News new | ask | show | jobs
by dudul 2742 days ago
Elixir's syntax may look more aesthetically pleasing than Erlan's, but Erlang's is way more consistent and simpler once you get used to it/understand the rules.
2 comments

What makes it interesting is that the syntaxes have (most likely) been designed with different goals. I can say that Elixir was designed with extensibility and meta-programming in mind. So there are some cases where I prefer the Erlang syntax (for example, I still find defining multiple function clauses each with a single expression more elegant and concise in Erlang) while there are other cases I prefer Elixir's syntax exactly because we were able to extend the language (such as the `with` special form for handling nested case expressions).

The funny thing is, if you try to add those features to the other language, they are usually refused. Erlang wants to avoid new syntactical expressions to keep it simple while Elixir's extensibility is bound to a set of limited AST rules (and we don't want to add new ones).

I both admire Elixr for making Erlang “cool” and detest it for ruining my single most favorite part about the language, it’s simplicity and clarity.

There’s only one way to do a given thing and you can learn each of the things the syntax can do in a weekend.

It was my first non-C-like, non-assembler language and I loved it.

When I give talks about Erlang I usually say I can teach the syntax in about 5 minutes. An exaggeration, but not a dramatic one.

I too vastly prefer Erlang’s syntax to Elixir’s. It helps me think like Erlang, and most of my functions are just a few lines long. Thanks Garrett[0].

[0]: http://www.gar1t.com/blog/solving-embarrassingly-obvious-pro...

My sentiment exactly :)

I'm grateful that Elixir is putting Erlang under the spotlights. That it is doing a lot to conveying all the Erlang/OTP concepts and practices. But each time I use it - and I know I may be the odd duck based on slack, blog posts, etc - I feel like the syntax is so complex, with 4 different manners to write the same thing. And I'm not talking about "ways to do things", but literally syntactic ways to do the same thing.

> literally syntactic ways to do the same thing.

Yup! They are not that many though (6 rules) and they are all documented here: https://hexdocs.pm/elixir/syntax-reference.html#syntactic-su...

Does the shorthand lambda belong on this list?

Thanks for all the work!

Oh, that's a very good question! It doesn't because the list linked above is about syntactical equivalence and the shorthand `&` has its own AST. But now you made me wonder if we should add it to the list anyway (with a caveat) as it would make the list more complete.
I think those more complicated things are there to make things easy for developers. The standard library is not that big, and the extra syntax is there for a reason - for example `with` is pretty fantastic for reducing `case` clutter (a real thing with erlang), and pipes are also great.

I don't love that there are two ways to make lambdas but it's nit the worst thing in the world.