This post was originally published on CodeCast by Tam Kbeili.
I strongly believe that Elixir is the best programming language to get started with the functional programming paradigm for many reasons. Here are a few of them:
Elixir leverages the Erlang Virtual Machines(VM). If you haven’t heard of Erlang, it’s a programming language introduced way back in 1986 to help telcos and many of them still use it to operate their equipment. Erlang has been built to be distributed, fault-tolerant, and performant. There is one small program with Erlang: Syntax can be very ugly. Check this page for an example.
Functional programming languages have their roots in math so they can be abstract with many complex algebraic data types. Elixir is dynamically typed and heavily inspired by the Ruby language which is probably the most simple and most elegant programming language out there. I have taught and used many programming languages in the past and always noticed that students accelerate their programming learning faster with Ruby than with other languages. It almost feels like Ruby as a language fades out and leaves students to focus on understanding and applying programming principles. Elixir is not far off from Ruby syntax-wise.
I do have to say that, generally speaking, object-oriented programming (OOP) is easier to get started with than functional programming. It’s much easier for the human brain to visualize objects that store states and interact with each other than many functions that call each other and pass data around. That said, functional programming has many benefits over OOP (I will get into this in another article). Elixir, I believe, is the best gateway language to functional programming and is very practical.
Historically, one of the tradeoffs when choosing a programming language has been elegance/simplicity vs performance. Ruby is very elegant but not performant, and C++ is very performant but complex. Elixir managed to find an amazing middle ground with beautiful syntax and high performance. Leveraging the Erlang VM, you get a good base level of performance. In addition, Elixir makes it very simple to run code in parallel, a task that usually takes understanding many hard concepts and writing not-so-easy code.
Running code in parallel is becoming more and more important as chip companies such as Intel are not able to cram more transistors into microprocessors, so we’re getting processors that have more cores instead. Parallelizing your program enables it to take advantage of the multiple cores. With Elixir, the task is significantly easier than using traditional languages that support multi-threading like Java.
For instance, some claim that Phoenix, the most Elixir popular web framework is 7X+ more performant than Rails, the most popular Ruby web framework. You can read more about that here.
Of course, you can write something more performant in say Java, Scala or C++. That said, I believe the potency of Elixir comes from the right amount of the key ingredients: performance, elegance, and simplicity.
Simplicity and performance are completely useless if you don’t have a vibrant community. Luckily Elixir has a growing and supportive community. Here are a few key indicators:
- There are key frameworks that are very mature in Elixirs such as Phoenix for web applications and Nerves for hardware
- There are libraries for most of the key operations you are likely to do Elixir
- Elixir conferences have become more frequent with growing attendance
- You are likely to find answers to most questions you face by Googling with yield results from StackOverFlow or ElixirForum
In conclusion, I highly recommend trying a sip of the purple and delicious Elixir to get transported into the functional programming wonderland. You will certainly like it!
If this blog made you curious about Elixir, you should definitely hop on to a live event I am doing on June 25, 2022. I will be discussing the basic building blocks of Elixir and will integrate with https://swapi.dev/ which is a fun open API that returns Star Wars characters and movie data. I will also be answering any questions you have and guide you.
Looking forward to seeing you there!