What are the main benefits of Elixir compared to Clojure?

Hey,
Just curious what are the main benefits of Elixir compared to Clojure?
When is Elixir more useful than Clojure and vice versa?
Thanks.

As they don’t run on the same virtual machine, You should look at the tradeoff they provide.

For a good definition of the BEAM, You can read the following post.

3 Likes

Erlang and Elixir (and likely any BEAM language) give you:

  1. 99% transparent parallelism and concurrency. I can’t stress enough how important this is and how I spent 15 years of my career trying to emulate this trait in at least 5 other languages (and failed like everyone else who tried the same).
  2. Lag-less operation: spawn 50_000 tasks and the runtime will give them all a fair treatment for as much as the hardware allows.
  3. Pre-emptive scheduling. No single task can slow down the others.
  4. Ability to structure your software as a tree of tasks and supervisors, with the supervisors restarting tasks if they fail. The so-called fault tolerance. This is EXTREMELY underrated and people usually come looking for this in Erlang and Elixir after suffering in other ecosystems for a long time. I haven’t met a single new programmer who is able to appreciate how much of a productivity boost and a reducer of stress this feature is but oh well, what can you do.
  5. Elixir-specific: macros. Basically code generators at compile time. Another vastly underrated productivity booster.

While other 30-year old languages like OCaml are still struggling to even produce a working multithreaded runtime (hope it doesn’t take them another decade to make an actor runtime!), and others like Rust are just now laying the foundations of a solid asynchronous multicore runtime (and Go never being that impressive in that regard to begin with), Erlang has been enjoying a multicore pre-emptive runtime for 20+ years, long before mainstream multicore CPUs even existed.

Many programmers underestimate these aspects, to their peril.

Elixir is one of the secret weapons in the programming area.

60 Likes

I respect Clojure and it was a strong influence on Elixir (more than Ruby IMHO). Here’s an old post I made in a related thread where I link to a document really comparing the JVM to the BEAM. It’s a great read. All sorts of little design tradeoffs were traded in different directions.

10 Likes

Clojure’s a darn nice language. It runs on the JVM.

No, really, that’s it. LOL the JVM might be an advantage or a disadvantage depending on your circumstances.

2 Likes

Elixir does not need 1 billion of parentheses. :slight_smile:

5 Likes

The parentheses give you the simplest most consistent syntax. That Elixir is lacking them makes things more complicated. :wink:

32 Likes

Perhaps painfully obvious but I will go ahead and make the points that:
• Clojure uses a LISP syntax which would be an advantage for folks coming from the LISP world. (Hat tip to rvirding and LFE)
• Elixir uses a Ruby syntax which might benefit those coming from a Ruby background.

Tail call optimization is built into the Erlang VM - Clojure has to work around the JVM on that front (I suppose that’s just a difference not necessarily a benefit either way)

Clojure can take advantage of the full breadth of JVM based libraries - Elixir has a smaller-but-growing ecosystem. I’m not sure who the advantage is on that front because a lot of JVM based software seems pretty poor and finding the truffles among the dirt can be challenging.

7 Likes

Well in any case I find jvm patterns to be difficult to read and hard to understand.

Elixirs patterns are just like butter. Phoenix is hard to get into. It’s very opinionated about how to do things and I think the organic discoverability is low (I recommend getting a book or a course that will hold your hand through the basics) but I find that all of Phoenix’s opinions are sound and well-considered.

Jvm documentation quality is lower than elixir, and lots of “spinach things” like unit tests (and consequently refactoring :grimacing:) are not as joyful, which means people do less of it.

3 Likes

Yep you can call functions in a mathematical way with no limits of arguments, and so on, but Sorry. I don’t like seeing a lot of them because it’s confusing (IMO). I know the power, but I prefer Elixir syntax. I think “makes things more complicated” is just a matter of opinion. I don’t like parentheses, you like parentheses. It’s fine.

At least opinions are not immutable so maybe one day you will start liking parens who knows :slight_smile:

4 Likes

Yes. Totally.

Opinions are immutable in the Functional world, but they can be transformed into something new :slight_smile:

3 Likes

Having things more complicated means that there are more rules and restrictions you have to know and follow. For example why do I have to put the first thing on the same line as the with, there doesn’t seem to be any logical reason for it but you must do it. Yes, I know why, but it would be nice to have the with on its own line.

Btw it’s the same reason as for if and function calls.

5 Likes

Clojure is in my opinion a wonderful language (like many LISPs), that shares quite a few things with Elixir: both are functional without being pure, both are dynamically typed but support some tooling around enforcing types, both rely on immutable data structures, both have powerful meta programming in the form of macros written in the language itself, and both are compiled into an intermediate form, making them especially powerful for long-running programs, less so for scripting.

Apart from the differences related to the JVM versus the ERTS, that others have mentioned, I would also mention some differences in the focus and practices of the community:

  • Elixir and Erlang are designed from the ground up to allow for concurrency through the actor model (Erlang processes). While it is completely possible to write concurrent software with Clojure (for example with channels), concurrency in the Elixir and Erlang world is a core value that permeates the design of the language and its libraries.

  • The Clojure community tends to promote small composable tools over frameworks. While Elixir also places a lot of value in small composable modules, its community also provides high quality frameworks like Phoenix and Ecto. This is totally subjective, but I personally like Elixir on this aspect.

At the end of the day, there is virtually nothing practical that one language can do and the other cannot, and they have many similarities, but they do have slightly different “core values”.

On the point of syntax, apart from the old jokes about parentheses, I learned to be mindful of familiarity bias: what looks strange and difficult to understand is not necessarily objectively worse or less readable. If a syntax is consistent and minimizes special exceptions (and that is certainly the case with LISP), it’s often just a matter of getting used to it. After learning and loving very different languages, I now consider “syntax looks strange to me” not a good reason for dismissing a language.

20 Likes

I’d advise asking this same question in https://clojureverse.org/

Some of these replies are not entirely accurate

1 Like

I find Elixir’s syntax to be quite fluid and forgiving, making it less complicated. There are less rules than JavaScript for example.

The compiler is also very good at telling you if something is ambiguous and how to correct it, further simplifying things.

As for with and if the first argument doesn’t need to be on the first line if you add \ after the function call. Even the built in formatter will do this if the line is too long.

There is also nothing stopping you from using parentheses everywhere if it’s easier for you to read, so it can really appeal to programmers from many backgrounds.

2 Likes

Does learning Clojure/Lisp make you a better Elixir programmer?

You can learn LFE if You want to become better at both :slight_smile:

Anyway, if You want to become better at Elixir, learn Elixir…

1 Like

Asking the question is answering it :wink: