If the context does not involve reference to software development, the names of Ruby and Elixir might have referred us to some video game like Heroes of Might and Magic or Warcraft. However, in the world where the code runs things, these names denote two programming languages widely used for building various sorts of software. Each of them has its own followers, as well as haters. In this article, we’ll try to find out their differences and answer several relevant questions like “which product type is the best to create using Ruby/Elixir” or “is Elixir more in demand than Ruby”. And we’re starting as per seniority.
As of 2019, Ruby is 24 years old. Despite the mature age, we cannot call it one of the oldest languages like C or Eiffel. The peculiar thing about the language is the lack of opinionated or straight-out ways of doing coding. In other words, several engineers can go different ways to execute something using Ruby. Despite this flexibility, the code you get is associated with elegance and usability.
Ruby is not a very popular technology (18th rank according to the TIOBE index as of January 2019), and many haters used to throw up predictions about its flame-out in the short run. Meanwhile, the language is keeping afloat, and its supporters are eagerly waiting for the debut of the 3.0 version in the next year.
Unlike Ruby, Elixir can be called a youngster because its first appearance was dated seven years ago. At the same time, it is based on one of the world’s oldest virtual machines titled BEAM, which, in turn, rests on the Erlang Open Telecom Platform. Actually, these links to relatives are not very interesting except for the fact that a Ruby engineer is the Elixir inventor! Fancy that. His name is José Valim, and a trigger to creating a new technology was his desire to optimize the performance of apps built with RoR in multi-core systems. In the view of this, we would suppose that both languages are like two brothers or a brother and a sister at least. Let’s try to figure it out.
Ruby is listed along with Python and Java because they are object-oriented languages. It means that everything including methods, numbers, and variables is an object. Elixir is not cut from the same clot. It’s a representative of the functional programming paradigm, which gives a completely different way of looking at concurrency, debugging, and testing. The focus is made on the computation of pure functions. Besides, this paradigm is quite efficient for building large programs out of small functions. However, it does not mean that object-oriented technologies are either better or worse. They’re just different.
Therefore, engineers who decide to switch from Ruby to Elixir should be prepared to think differently. For example, you need to avoid changing state; variables cannot be redefined with another value; all data is immutable, etc.
Many Rubyists say that the language they use is full of magic in a good sense of the word. And the clear syntax is always referred to one of the major benefits you get. Matz, Ruby inventor, says that the language offers concise, yet readable code. Other experts spare no praiseful words and characterize Ruby’s syntax as mellifluous and simply elegant.
Well, we cannot say the same about Elixir. Erlang, its underlying language, can boast one of the most consistent syntaxes among other technologies. For some reason, Elixir has not inherited this hallmark. The clumsy syntax is often considered one of its drawbacks and disappointments. Many engineers hate the language’s inconstancy which involves the possibility to write the same thing in many different ways. Opinions about the Elixir’s syntax are ambivalent. At the same time, both languages share some similarities in this regard.
Performance has never been Ruby’s cause for pride. Though the language showed better results with every new version, it was not enough to reach a significant speed enhancement. However, the latest release dated of December 25, 2018, promises to ruin this statement, since the latest version, 2.6.0, provides the 1.7x faster performance compared to the previous one, 2.5.3. So, there is hope that Ruby may get rid of a slow-programming-language cliche. And what about Elixir?
José Valim reached his goal of creating a technology that works faster than Ruby. Indeed, Elixir excels the Yukihiro Matsumoto’s brainchild (Ruby) in performance and scalability due to being optimized for maximum speed on the compiled code in the already running Erlang virtual machine. And the trump card is multiple cores support which allows you to do things in parallel, like run tests, for example. Elixir is faster than Ruby according to many benchmarks. At the same time, there are some cases across the web, which show the opposite result due to some improper usage of the languages under comparison. Therefore, it’s important to have an advanced understanding of modern high-performance dynamic optimizing compilers, statistics, hardware architecture, and a bunch of other details to write relevant benchmarks.
When talking about web app development with Ruby and Elixir, we cannot but mention Ruby on Rails and Phoenix – the frameworks built atop the languages. Rails is known for its demand on the market. The evidence of this is many big names which have opted for the framework for their products. These include Dribbble, GitHub, and also a bunch of other businesses. Besides, numerous web app building companies like Railsware base their activities on leveraging RoR. It’s not enough to name the framework awesome. Rails is time and cost efficient solution characterized by such benefits as fast prototyping, MVP design pattern, test-driven development approach, the convention over configuration paradigm and other magic. And do not forget about a large vibrant community of engineers. All that makes RoR an ultimate tool for building web products.
Phoenix, in turn, is usually referred to a Rails imitation written in Elixir which is far from the truth. Some ideas were indeed borrowed from Ruby’s framework, but in general, the resulting tool brought innovative solutions to many technical problems. And these solutions turned out much better than those of RoR. Many experts acknowledge that Phoenix prevails RoR as for stability, speed, and hot deployment. Meanwhile, the frameworks differ in programming paradigm (functional vs. object-oriented), database tools (Ecto vs. ActiveRecord), third-party software pieces (packages vs. gems), and other elements. At the same time, the visibility of Rails keeps its Elixir-based rival in the sidelines on the market.
Despite the above, both solutions share a single problem of the talent shortage. It’s a challenge to find a good Rails developer, not to speak of Phoenix-savvy engineers. However, some experts put forward assumptions that the mentioned issue will be solved in the coming years. We’ll see.
Elixir = New Ruby?
It’s an unwise practice to say that some language is bad and another one is good. The truth is that each solution has its benefits and drawbacks. Another thing is that special requirements of a particular project demand its owners and managers to seek out the most applicable technology. Elixir does excel Ruby in performance and scalability. However, it lags behind as for talent availability, size of ecosystem and productivity. So, they are different in nature and in purpose. Thus, if a goal is to deal with high-traffic systems or IoT, Elixir would be a smart choice. Ruby is more suitable for building MVPs, as well as fast and secure web apps.