The Magical Elixir
Tags: elixir, programming, learning
Published: 2024-02-28 03:56:04

I first saw Elixir at That Conference in Wisconsin sometime between 2015 and 2018, I really can’t remember. Ryan Cromwell was giving a talk on it and I was fascinated by it in less than 1 hour. I set out a goal to learn the language. You’ll notice that it is 2024, so you see how that went.

## Why Elixir?
There is about a 0% chance I will use Elixir in my current role at work, so why go through the effort. Elixir is on a different spectrum from my primary languages of C#, JavaScript, and Go. It’s functional, it’s dynamically typed, there are no classes, interfaces, or for loops. I find it beneficial to learn how other languages solve problems in a different way and this one definitely checks the box for ‘different’. My hope is to see how I could have solved prior problems with a different mindset. I am not interested in determining if Elixir is better or worse than languages I already know. I want to see how it is different and where the differences can be beneficial to my thinking and reasoning in the future. Last reason for learning Elixir, I find this fun - I have been writing code in some form for over 20 years and never tire of learning new things. I know languages are not the most important part of software engineering, but I find the diversity in languages fascinating.

## The book
Reading book. The book is dense, in a good way. This assumes you have experience in at least one other language as there are allusions to concepts in other languages. The first 3 chapters cover the Erlang platform, language constructs, basic types, and higher order functions. I am not going to regurgitate the book, but take note of things are foreign to me based on my experience. 

After reading about a third of the book. I felt this was an appropriate time to review my notes from what I read, write some code and reflect on it.

## Initial Thoughts
I have really never done a deep dive into a functional language. FP definitely has its detractors, but I'm determined to understand why the haters don't like it and why the fanboys think its the best. So far the functional style is, different. I understand the constructs and see it as almost declarative instead of the traditional imperative.

Dynamically typed language. I have always used statically type languages (and JavaScript, where ever that falls in the spectrum). I'm supposed to defend and say statically typed is better, right? I think I need to embrace the dynamically typed life for a bit before making an opinion. 

Elixir has some features that are new to me and also fascinating. `Atoms`, `macro everything`, `pipe operator`, `tail call optimization` and `pattern matching`. These feature really open a new world of thinking when it comes to writing and reasoning about code. Event the simplest of them, `atoms` open up so many ideas of how I could have used something similar in the past. I'm really excited about these language features.

There are a few features that are 'missing' from the language. `for loops` and `no arrays`. I know there are recursive lists that will the role, but arrays and for loops seem so primitive and basic to every language I have used. I'm sure I will learn the idiomatic ways to process data with lists instead of array, but it will take some time.

## What's Next?
I'm spending some time on the [Elixir Playground](https://playground.functional-rewire.com) just to get comfortable with the syntax. I plan to continue with the book and start writing code in an IDE. 

If you have advice regarding Elixir or just want to share your experience, I'd love to read your comments to this.