9

What are the main benefits of Elixir compared to Clojure?

 4 years ago
source link: https://elixirforum.com/t/what-are-the-main-benefits-of-elixir-compared-to-clojure/29959
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Chat / Discussions

clojure

alice March 20, 2020, 7:23pm#1

Hey,

Just curious what are the main benefits of Elixir compared to Clojure?

When is Elixir more useful than Clojure and vice versa?

Thanks.

kokolegorille March 20, 2020, 8:20pm#2

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

dimitarvp March 20, 2020, 10:09pm#3

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.

15 Likes

gregvaughn March 20, 2020, 10:47pm#4

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.

6 Likes

sribe March 21, 2020, 12:11am#5

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

tiagodavi March 21, 2020, 12:53am#6

Elixir does not need 1 billion of parentheses. 7JBJ7fb.png!web

rvirding March 21, 2020, 2:46am#7

The parentheses give you the simplest most consistent syntax. That Elixir is lacking them makes things more complicated. qa6RFv7.png!web

6 Likes

easco March 21, 2020, 4:13am#8

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.

3 Likes

ityonemo March 21, 2020, 4:23am#9

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 A7jU32E.png!web ) are not as joyful, which means people do less of it.

tiagodavi March 21, 2020, 12:55pm#10

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.

alice March 21, 2020, 1:12pm#11

At least opinions are not immutable so maybe one day you will start liking parens who knows 7JBJ7fb.png!web

tiagodavi March 21, 2020, 1:18pm#12

Yes. Totally.

kokolegorille March 21, 2020, 1:24pm#13

Opinions are immutable in the Functional world, but they can be transformed into something new 7JBJ7fb.png!web

rvirding March 21, 2020, 3:01pm#14

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.

lucaong March 21, 2020, 5:09pm#15

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.

8 Likes


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK