What are the main benefits of Elixir compared to Clojure?

栏目: IT技术 · 发布时间: 4年前

Chat / Discussions

clojure

#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.

#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

#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

#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

#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

#6

Elixir does not need 1 billion of parentheses. What are the main benefits of Elixir compared to Clojure?

#7

The parentheses give you the simplest most consistent syntax. That Elixir is lacking them makes things more complicated. What are the main benefits of Elixir compared to Clojure?

6 Likes

#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

#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 What are the main benefits of Elixir compared to Clojure? ) are not as joyful, which means people do less of it.

#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.

#11

At least opinions are not immutable so maybe one day you will start liking parens who knows What are the main benefits of Elixir compared to Clojure?

#12

Yes. Totally.

#13

Opinions are immutable in the Functional world, but they can be transformed into something new What are the main benefits of Elixir compared to Clojure?

#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.

#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


以上所述就是小编给大家介绍的《What are the main benefits of Elixir compared to Clojure?》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

精通 CSS(第3版)

精通 CSS(第3版)

[英]安迪•巴德 - Andy Budd、[瑞典]埃米尔•比约克隆德 - Emil Björklund / 李松峰 / 人民邮电出版社 / 2019-2 / 99

本书是CSS设计经典图书升级版,结合CSS近年来的发展,尤其是CSS3和HTML5的特性,对内容进行了全面改写。本书介绍了涉及字体、网页布局、响应式Web设计、表单、动画等方面的实用技巧,并讨论了如何实现稳健、灵活、无障碍访问的Web设计,以及在技术层面如何实现跨浏览器方案和后备方案。本书还介绍了一些鲜为人知的高级技巧,让你的Web设计脱颖而出。一起来看看 《精通 CSS(第3版)》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

URL 编码/解码
URL 编码/解码

URL 编码/解码