Elixir, First Impressions

Patrick Wendo - Jun 26 '22 - - Dev Community

I have often thought of going into a functional programming language. Elixir has been on my radar for a while and after some research into the language, I finally decided to dip my feet into it. And it's an interesting language to say the least.

Elixir Background

I have never had to get into the background of a language's creation in order to get a better understanding, but for Elixir I did. Not because I had to but because I wanted to. Elixir is built for the Erlang Virtual Machine. Erlang the language is similarly built for the Erlang Virtual Machine. And it was designed for high availability. What this means is that it is built to withstand failures and avoid downtimes. This renders itself very useful for systems that require this feature, say, reservation systems for instance. Erlang however is more than just a programming language. It is a unit made up of 4 parts, the language, the virtual machine, the framework (OTP - Open Telecom Platform) and the tools. Erlang and Elixir both compile into bytecode that runs on the Erlang virtual machine.

Semantically, many Elixir constructs map to Erlang constructs, making it such that anything you can do in Erlang, you can also do in Elixir. Elixir just tends to be cleaner and easier to read than Erlang. (IMO this is because of the Ruby influence. Ruby was built to be a language for humans to enjoy reading and that holds up. (Might just be familiarity bias though)) Speaking of Ruby, Elixir has a lot of influence from other languages, but I particularly liked that it was influenced by Ruby because I am a Rubyist at heart. So finding some things stay the same was rather welcoming.

The Ecosystem

I'm still learning about it, so this is very patchy based on what I have experienced. I found the elixir subreddit, and some github repositories for beginners. But other than that I'm still searching. If I could find a local group that works on Elixir that would be so welcome. If you know of any slack channels or other online communities, comment down below.

Coding Experience.

Typically I learn by doing. So I will read up the docs, or whatever guide book I am using and then go to Codewars and just start grinding on questions. What this does is that it helps me get used to the documentation. How to read it, and how to navigate it. Not all documentation is the same. I also found that coming from an OO background, this helps me practice thinking with a functional programming mindset.

Codewars lets you rank up from 8th kyu upwards, so once I rank up a level or two, I normally decide to build a small project. Currently I am working on a script that will either return a single video game quote or you pass a number parameter and it will return multiple quotes. This helps with understanding data structures, functions and iteration. This small project is what made me happiest today. Elixir uses a build tool called mix that bootstraps your project for you and well, I was impressed.

Mix

When you initialize a new project using mix, it will scaffold the entire library for you and add in a test framework as well. Beyond that, mix also comes with a built-in formatter. The formatter.exs file allows you to define rules for formatting, but also has predefined defaults. What this means is that your elixir project and someone else's will almost always have the same styling. It also has positive implications for CI/CD. I am still learning what else mix can do, but it's looking good so far

Final Thoughts

It's been a while since I spent this much time working on learning a new language. I do not want to do those #30daysofcode challenges cause I have never had good luck with those, but I will certainly keep hacking away with Elixir and see what potions I can concoct. I haven't even gotten started with Phoenix. Can not wait to see how that is compared to Rails.

TLDR: Elixir is pretty damn cool.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .