Wednesday, March 10, 2010

How Much Has Scala Influenced Erlang?

This question was recently overheard at qcon. On the surface it seems like a rather silly question but after some digging I think the answer might surprise you.

Scala and Erlang have actually gone back and forth, sharing ideas, for quite awhile now. While many people don't realize it, Erlang was first implemented on the JVM. This is back in the 1.x days when Java was using green threads. Joe had seen that this was a great platform for distributed, low latency, high throughput, concurrent applications and wrote a quick language implementation that quickly grew into Erlang. Martin Odersky has stated several times that Erlang was his influence for implementing Scala on the JVM. It was at this point that Scala introduced actors. While not a new concept, Scala was one of the first major implementations of actors. Erlang originally used a dataflow concept similar to what Mozart/Oz would later implement.

Why, you may ask, did Erlang finally move off the JVM? Such a great platform, you would expect them to stay. The answer is tail calls. The JVM has always lacked tail call optimization and Erlang needed it. Trampolining just was not sufficient for how Joe wanted to structure programs. So they ditched the JVM and implemented their own VM (known as beam). At this point, since Erlang was off the JVM, Sun (now Oracle) decided to drop the green threads for a more traditional threading implementation. While this transition may seem weird, it actually gave birth to what many people consider the most powerful part of Erlang: fault tolerance. Because Joe wanted to move off the JVM as quickly as possible he had people use his unfinished VM, which was very buggy. A lot of the fault tolerance aspects of Erlang come from people trying to work around Joe's buggy VM, which thankfully is quite stable now.

Richard Virding was nice enough to give us a little rundown on what it was like in the early days of moving from the JVM to beam (from #erlang on freenode):

< MononcQc> Did the need for distribution have anything to do with your move from the JVM?

< rvirding> No not at all, Terracotta implemented everything we wanted, and better, it was really the tail calls that pushed it.

< rvirding> I can remember one night late with Joe we were trying to get our own distribution layer worker and we were having trouble with the security model.

< rvirding> Joe had just happened to be playing with Netscape that day and saw this idea they introduced called 'cookies' and he said "Richard, I've got it!"

All of this makes a lot of sense when you think about it though. Given the popularity of Scala and that it was a forerunner to Erlang's style of programming you can see why there are so few Erlang books. It also becomes clear why Erlang has such a hard time penetrating the market. You can pretty much pick up Erlang just from a Scala book and at that point, why not just use Scala?


  1. Can you provide any evidence to support your assertions that Erlang *ever* ran on the Java Virtual Machine.

    Funny that this is not mentioned in the official history of the Erlang language:

    Also, the BEAM VM for Erlang was already in production use in 1993. Before Java was even on the scene in 1994.

    Oh, and Scala was not invented until 2006, more than 20 years after Erlang:

    "Scala was the forerunner to Erlang's style of programming". Please.

    I call complete BS on this entire article.

  2. Oh, and see section 10.25 of this post:

    "10.25 Could the Java Virtual Machine be used to run Erlang? [...]There are a couple of obstacles: the JVM does not provide support for tail recursion or tagged data types. Both of these deficiencies can be worked around at a cost. The result will probably be slower and use more memory than a VM written for Erlang. [...]"

  3. Not a single thing in this article makes any sense.

    Erlang was originally written in Prolog in the 1980s, it's not even a young language and to my knowledge never existed on the JVM.

    Before BEAM there was JAM, which was Joe's Abstract Machine. Joe Armstrong implemented this one.

  4. Let me add to the confusion: Erlang does actually run on the JVM; source code here: and blog:

  5. Wow Kresten, great job. Where did you get your hands on the original Erlang JVM code?!

  6. HAH, Hook, Line AND Sinker...great job orbitz!

  7. It's really a shame Erlang didn't stay on the JVM and instead decided to write their own crappy VM. Until then pragmatic companies like Twitter will use Scala because it is clearly the best technical decision given their needs, and Erlang messaging systems like RabbitMQ could finally outperform superior ones written by Twitter employees in Scala, like Starling.

    Now the Erlang people are just playing catchup to Scala, stealing ideas left and right in order to shore up their crappy language. Had they just stayed on the JVM none of this would be a problem. What a shame.

  8. This article is a complete BS. You even got the name wrong, the guy is Robert Virding, not Richard.

  9. It's interesting when you think about it. The original implementation of Java was written on the Parrot VM, which in turn was little more that set of Microsoft COM services. So you see we've come full circle.

  10. James, that is a really good point. I'm considering working on a New York Times article going into a lot more detail about the history of Scala and Erlang. I may hit you up for some talking points later on.

  11. This blog post has opened my eyes and made me feel like finally taking the big step and renaming 'Learn You Some Erlang' to 'Learn You Some Scala'. The book will be good enough for both languages anyway. As said in the blog post, they're roughly the same (especially the actors).

    I would also like to thank Richard Virding, who has always helped me a whole lot, mainly to install the JVM to run Erlang on it.

  12. I remember using an early version of Pizza on my C64 and reading about Erlang (then called Earlang) in an issue of Compute!. I believe they had a sidebar showing how to write a joystick doodle app using Earlang; contrasting it with Pizza. The languages were almost identical! I've since moved on to imperative languages like Clojure and Microsoft's Entity Framework.

  13. Is this an April Fool's Joke that got leaked?

  14. What impresses me the most is that during all of Glenn Rempe's extensive link gathering he never once stopped to think "maybe the author already knows this..?".

  15. @nh82

    Yeah, call me 'punked'.

    It took a bit of digging to find that the author is the (former) author of:

    Being new to Erlang myself, I'm now quite certain he knows more than I on the topic. That's doesn't excuse what I still view as his rather lame attempt at sarcasm. Unfortunately, like myself there are lots of people that found this post who had not followed his blog in the past. This post made it onto lots of Erlang/Scala related lists and I'm sure raised the blood pressure of more than a few.

    To what end? I still don't know.

    Yes, this is apparently a joke. Lolz.

  16. Disbelief, shock, anger. These are the emotions we all felt when we learned Erlang was moving off the JVM>

  17. No. I don't agree with you about the opinion that Erlang did ever move to JVM. And emotions because of some ridiculous opinion are different from emotions because of some amazing fact.