Elixir vs Ruby — where to use?
Originally I posted this material on Syndicode blog.
I work in a Ruby on Rails agency, and we choose Ruby as our main programming language. But at the same time, we do use Elixir for a big part of our projects. How do we know when to use one of these programming languages? Here is the summary of the decision-making process for ‘Elixir vs Ruby — where to use?’
Recently I decided to make the primitive comparison of Elixir and Ruby.
About competitors in a nutshell
- Ruby was created in 1993 by Yukihiro Matsumoto for ‘developers happiness’. Its main framework is Ruby on Rails.
- Elixir was created in 2011 by José Valim to be the real ‘ concurrent language’. Its most popular framework is Phoenix.
Pros and cons of both Ruby and Elixir
- Battle-proven solution — it is based on Erlang VM (BEAM), the oldest virtual machines in the world, that remains broadly used. Elixir has a full access to Erlang functions.
- Performance — Elixir is a compiled language.
- Elixir’s documentation is very good. It covers everything and always helps to solve any problem you may have. It’s also always available from the terminal.
- OTP — Open-Telecom Platform is a set of tools for writing concurrent programs easy and fault-tolerant by providing a generic framework on top of which you can write your applications.
- Lack of developers — Elixir is still a fresh programming language, there may not be too much talent on the market with expertise in it.
- Smaller ecosystem — Elixir is relatively young, there are fewer libraries around for it than for Ruby. This means that you might have to write features from scratch that you would get by simply importing a gem in Ruby
- Clean syntax — Ruby has a very clean syntax that makes code easier to read and to write. Since it was created to make developers happy, it’s very easy for the newbies to enter Ruby.
- Ruby on Rails framework — it changed the way we write web applications, you can achieve so lot by writing so little code. It also made prototyping applications faster.
- Ruby has a large ecosystem of tools and libraries for just about every use. Such as ORMs (Active Record, DataMapper), Web Application Frameworks (Rails, Sinatra, Volt), Virtualization Orchestration(docker-api, drelict), CLI tools(Thor, Commando), GUI Frameworks(Shoes, FXRuby) and more.
- Productivity — Ruby is a really expressive language. A couple of code lines in Ruby can do the same job as several scrollings of code in other programming languages.
- Harder to maintain — Many Ruby libraries and tools use magic behind the scenes to keep the code concise. So when you face the situation when something went wrong, you can’t really fix ‘the inside’ issue. Also, there's no ‘good practices’ out of the box introduced in Ruby.
- Performance — Ruby was never meant to be one for performance. You may think that this only affects production speed, but it’s not. Technically, if you will take the ‘right’ project you will never face such problem. (In this material I will set some examples of the perfect projects for Ruby and for Elixir).
Elixir vs Ruby — where to use?
Elixir is your choice if you want to develop:
- concurrent connections
- high-traffic systems (like chat servers with multiple rooms)
- distributed systems
- systems that do stuff asynchronously
and other apps and services able to handle 100–1000000 simultaneous connections per computer.
Ruby is your choice if you want to develop:
- fast and secure web or mobile apps
- systems that nicely divide into smaller subsystems
and other interactive, with some kind of built-in functionality web apps and web services.
One interesting moment! Elixir is really awesome. But Functional programming paradigm is a different approach from object-oriented languages most programmers used to. So despite Elixir is as approachable as Ruby it is still a niche language. Elixir needs more time to become as spread as Ruby. Nowadays it’s harder to find experienced and talented Elixir developers. But there are many newbies who were recently attracted by Elixir.
I wonder, what is your consideration when you choose between Ruby and Elixir?
Thank you in advance for your thoughts and comments!