106

This question is in the context of the Beam VM and the capabilities that it provides, not in the general context of what a Turing complete language can do. I want to invest some time to learn either pure Erlang or Elixir. I get the basic differences between the two and I am leaning towards Elixir because of the macros, better syntax and faster development of the language this day.

My question is: if I choose Elixir, will I stumble on something that I cannot do in it, but can do in Erlang? Can I use all the OTP stuff, all the Erlang libraries, code reload, etc. with Elixir?

I am not asking for someone's preference between the two; just facts about the possibilities of the languages. Preferably from someone who used both in production.

Jonathan Leffler
  • 666,971
  • 126
  • 813
  • 1,185
Saša Šijak
  • 7,295
  • 5
  • 41
  • 74
  • You can do everything with Elixir what you can do with Erlang but there are a lot of variables that can lean your choice towards one or another and those variables are known only to you. – NoDisplayName Jun 22 '16 at 10:11
  • 20
    @hedgehog not an opinion, fact. question is "My question is if I choose Elixir, will I stumble on something that I can not do it, but can do in Erlang? Can I use all OTP stuff, all Erlang libraries, code reload, etc. with Elixir?" and the answer is based on facts not opinion. – Saša Šijak Jun 22 '16 at 10:16
  • 4
    For that question, the answer is: everything you can do in Erlang is possible in Elixir. But the title suggests that the question is what should you invest in and here the answer is "it depends". What do you want to do? For web applications Elixir is much nicer, because it was created to solve this problem. For some kinds of distributed systems you can find simplicity of Erlang superior. Lack of features is often the good thing. Learning only Erlang will help you focus on the most important bit: OTP. – tkowal Jun 22 '16 at 10:20
  • 2
    @SašaŠijak I changed the title of the question, to IMO better reflect what it's about - revert if you don't agree. – Paweł Obrok Jun 22 '16 at 13:07
  • 2
    @PawełObrok great edit, it rightly summarize what I was interested to know – Saša Šijak Jun 22 '16 at 13:29
  • I don't know Erlang or Elixir, but I do know that the answer to any question that looks like this one is "Turing equivalence". Any programming language powerful enough to meet certain (very minimal) standards, powerful enough to be a general-purpose programming language at all, is powerful enough to do anything that any other general-purpose programming language can do. That doesn't necessarily mean that they can all do everything *as easily as* each other, just that they can all do all of the same things, one way or another. – Mason Wheeler Jun 22 '16 at 14:18
  • 3
    everytime i make these kind of questions i get -10 downvotes – arisalexis Jun 23 '16 at 08:41

4 Answers4

66

You shouldn't stumble on anything you can do in one that you can't in the other, since you can freely call Elixir code from Erlang and vice-versa. You can even easily mix Erlang and Elixir files in one project.

In Elixir:

:erlang_module.erlang_function(args)

in Erlang:

'Elixir.ElixirModule':elixir_function(args)
Paweł Obrok
  • 21,259
  • 8
  • 72
  • 67
  • 3
    It can sometimes be a little tricky when building releases with nested dependencies or other very specific cases but I think this is definitely the right answer. **NOTE** : if running on very resource constrained machines, adding Elixir and Elixir dependencies to a release could be heavier in terms of memory. So if I am not mistaken, it can sometimes happen that sticking to pure Erlang might have the benefit of saving a few Megabytes of memory, making it easier to avoid crashes when there is no space left to expand the VM. – Laymer Nov 27 '18 at 12:10
39

Just to preface - I have only used Elixir in production and not Erlang.

I would honestly recommend Elixir. This is my opinion and not necessarily the right one for you, but below I will list my reasons why.

  1. Productivity: I come from a Ruby/Rails background so the Elixir syntax and style is something that was very familiar to me. One of the main factors that helps me determine whether or not to learn a language is how productive I can be in it - mainly why I chose Ruby. Elixir is the same. I can work just as fast in it as I can Ruby with all the added benefits of concurrency and pattern matching.
  2. Erlang: Since Elixir is built on top of Erlang and compiles down to erlang and the beam vm, you have access to every erlang module and package. So if you are worried about using elixir and missing out on all of the features of Erlang, you shouldn't be. Elixir even has it's own implementations of most of the bigger Erlang/OTP features such as GenServer, GenEvent etc.
  3. Community/Resources: The Elixir community is really a great one. The slack channel is really popular and great way to get some answers for beginner questions. There are already some really good books written on the language (Programming Elixir 1.2 - Dave Thomas, Author of the Ruby Pickaxe) also that make getting into the language really easy.

Really, if you have a mess around with the two you will probably come to the same decision that Elixir is a much nicer language with all the features of Erlang + More. It's on the rise as well, I can't remember the exact numbers but I remember reading something from the Hex website (package manager) about a considerable increase in package downloads.

Harrison Lucas
  • 2,541
  • 15
  • 23
  • 18
    Elixir does not compile down to Erlang, it compiles down to BEAM code. Elixir is NOT similar to coffeescript, et. al. that just write JS. – Peter R May 07 '17 at 14:36
38

TL;DR - Start with Elixir

Erlang has a steeper learning curve compared to Elixir. Once you start learning Elixir, you will automagically start learning Erlang. Hence, start out with Elixir. Elixir is written in Erlang and Elixir. See distribution on Github (since Elixir is full of macros aka meta-programming). Elixir Project Code distribution

You can use Elixir with Erlang and vice-versa, hence the full Erlang eco-system of 20+ years of libraries.

More details from Erlang Solutions

Elixir’s ‘out of the box’ productivity is accomplished by a strong focus on tooling and convenience in expression of data manipulation. System design is the same in Elixir and Erlang, but Elixir removes a lot of boilerplate code and is easier to extend. The removal of boilerplate raises productivity and allows programmers to get feedback faster – crucial when you want to launch your product to market as fast as possible. Less boilerplate also makes for happy developers, and happy developers are unsuprisingly productive developers.

Joe Armstrong's (Erlang inventor's) blog post about Elixir

Start here to learn about Elixir - Getting Started

Once you feel its going well, work your way towards practicing on Exercism and other resources.

Monolo
  • 17,926
  • 16
  • 63
  • 102
Sairam
  • 2,158
  • 19
  • 30
  • Some online sources claim that plain Erlang has better computation performance than Elixir. Is this difference important in practice? – Mikko Rantalainen Dec 13 '20 at 10:12
  • for some developers, expressiveness over speed is important for productivity, which is one of the reasons languages like Ruby, Python were chosen over C, C++. Its all tradeoffs – Sairam Dec 21 '20 at 15:56
  • Yes, I agree that it's always a tradeoff. Otherwise everybody would still be writing everything in assembler even today, just like it was done in 1960s because in theory that results in highest possible runtime performance. However, I was asking *how big a runtime performance tradeoff you're taking in practice if you choose Elixir over Erlang*? – Mikko Rantalainen Jan 20 '21 at 11:21
  • 1
    I am not sure about the current runtime performance tradeoff – Sairam Jan 20 '21 at 11:51
5

There are a few things. I think you can't make a recursive anon function in Elixir. Now to be fair this is something that in 8+ years of Erlang I don't think I have ever needed to do, and if I did it could be done easily in some other way. There are probably a few other things like that that quite honestly you can ignore.

In general, for things that most people care about anything you can Do in Erlang, you can do in Elixir and vice versa. The community on the Elixir side seems to be more active so I would suggest starting there. I have recently moved from Erlang to Elixir and with the exception of a few fancy things in Proper I can say that it is a pretty easy transition

Zachary K
  • 2,979
  • 1
  • 26
  • 36