With the challenges facing Ruby and Rails, many are finding Elixir as a good alternative, especially considering performance and concurrency.
But this isn't just because it is somehow faster--it is more memory efficient, better with streams, parallel and concurrent than Ruby, and this means you typically have better applications. But if you are just doing CPU bound things, they probably will bench roughly equivalently.
Functional vs Imperative
The gains are fundamentally about functional programming, which is different from imperative programming (the latter being what most scripting and OOP languages are, including Java, Python, C, etc).
Even experienced programmers get confused over the semantics, so don't let it cause you pause if you aren't sure what the difference is. I will explain things at a high level, but there are better in-depth guides for explaining the value of functional programming. Furthermore, being 100% pure functional is actually almost unattainable, so don't stress about that either!
At a simplistic level, functional programs behave around immutable variables, which means you don't get any unexpected side effects. But programming is inherently about changing the state of something, so how do you change a variable that is immutable? By calling a function, of course.
There are a variety of discussions about the differences, but at a high level functional languages help make faster and less buggy code, because of their inherent nature, which includes:
- Functions calling functions (and recursion is important)
- Avoiding side effects to your data
- Very Parallelizable
If you understand what the difference is between the stack and the heap, then one way to think of functional languages is that there is no heap. You cannot create nor use shared memory. Everything is allocated on the stack (within the function's memory space, as it were) and after the function exits, everything is implicitly reaped back in.
Now consider how that would work with objects, or nested dictionaries in other languages... and how often data changing unexpectedly (see #3 above) has caused you hours of painful debugging.
From this vantage point the functional language begins to show its value.
To help people explore possibilities with Elixir, I've gathered some information together.
Elixir looks a lot like Ruby, by design, but it runs on top of the Erlang beam, which has existed for some time--this has influenced its behavior and concepts, to a degree. This also means there are some packages that can be leveraged across both platforms.
- Elixir for Rubyists
- Elixir the New Wave?
- When to use Elixir vs Ruby/Rails
- Language Constructs are different:
- Iterating is different
- Pattern Matching is a very powerful polymorphism - think of it as describing how you want to see your data before the function is called, rather than poking and investigating the data after it arrives to decide if you like it's shape.
- Phoenix rather than Rails
- Phoenix for Rails Developers (book)
- Understand Elixir Processes - how to leverage the power of Elixir's concurrency.
- Understanding Supervisors
- Using the system:
- Who uses Elixir?
- Pragmatic Studio's Elixir (first few sections are free)