alice #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.
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 #3
Erlang and Elixir (and likely any BEAM language) give you:
- 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).
- Lag-less operation: spawn 50_000 tasks and the runtime will give them all a fair treatment for as much as the hardware allows.
- Pre-emptive scheduling. No single task can slow down the others.
- 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.
- 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 #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 #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 #6
Elixir does not need 1 billion of parentheses.
rvirding #7
The parentheses give you the simplest most consistent syntax. That Elixir is lacking them makes things more complicated.
6 Likes
easco #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 #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 ) are not as joyful, which means people do less of it.
tiagodavi #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 #11
At least opinions are not immutable so maybe one day you will start liking parens who knows
tiagodavi #12
Yes. Totally.
kokolegorille #13
Opinions are immutable in the Functional world, but they can be transformed into something new
rvirding #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 #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?》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
电子商务:管理与社交网络视角(原书第7版)
(美)埃弗雷姆·特班(Efraim Turban)、戴维.金(David King)、李在奎、梁定澎、德博拉·特班(Deborrah Turban) / 时启亮、陈育君、占丽 / 机械工业出版社 / 2014-1-1 / 79.00元
本书对电子学习、电子政务、基于web的供应链、协同商务等专题进行了详细的介绍,全书涵盖丰富的资料以及个案,讨论了Web 2.0环境内的产业结构、竞争变化以及对当今社会的影响。另外,本书在消费者行为、协同商务、网络安全、网络交易及客户管理管理、电子商务策略等内容上都有最新的改编,提供读者最新颖的内容,贴近当代电子商务的现实。 本书适合高等院校电子商务及相关专业的本科生、研究生及MBA学员,也可......一起来看看 《电子商务:管理与社交网络视角(原书第7版)》 这本书的介绍吧!