/ Developers

Learning Elixir & Why Functional Matters

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:

  1. Functions calling functions (and recursion is important)
  2. Immutability
  3. Avoiding side effects to your data
  4. 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.

Exploring Elixir

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.

Useful info:

Courses

Brandon Gillespie

Brandon Gillespie

Brandon loves Tech and has a breadth of experience including hands-on Implementation and Leadership Roles across many companies including small startups, enterprises, and the USAF.

Read More