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.
Top comments (7)
If you know how to design effective supervision trees which is a skill in itself.
For the longest time Designing for Scalability with Erlang/OTP: Implement Robust, Fault-Tolerant Systems was one of the best ways to learn about OTP.
"Note how we have grouped dependent processes together in one subset of the tree and related processes in another, starting them from left to right in order of dependency. This forms part of the supervision strategy of a system and in some situations is put in place not by the developer, who focuses only on what particular workers have to do, but by the architect, who has an overall view and understanding of the system and how the different components interact with each other." (p.175)
Though perhaps these days Designing Elixir Systems with OTP works just as well. However it doesn't hurt to have some fluency in Erlang in order to get access to some of the deep dive material.
"When we were designing Erlang and the basic ideas of how to use the language features we were thinking more along the lines of operating systems rather than of applications. I tend to think of it not so much as a language with concurrency but more of an operating system with a language." [ref]
You have to be careful because it isn't uncommon for individuals without prior exposure to a (single paradigm) functional language coming from Ruby to be lead astray (confused) by that familiarity - i.e. it can get in the way. The concurrent programming aspect just piles on top of that. You have to realize as quickly as possible that you are "not in Kansas anymore".
[ref]
So something like Learn Functional Programming with Elixir may be helpful to get some distance from Ruby.
In terms of mindset I think this is relevant:
Again, the issue is that you will try to solve problems with familiar patterns that are not relevant or even potentially counterproductive in Elixir/Erlang so some up front training/learning is probably a good idea.
Typically you find that you have to do without the creature comforts from the much larger ecosystem that you may have grown accustomed to. If you can get past that it is very easy to get enthusiastic about Phoenix/Ecto.
This is amazingly in depth. Do you mind if I contacted you with more questions regarding elixir? Probably though email?
My information is about two years out of date but I figured I share with you what I found beneficial while I was learning Elixir/Erlang and I have observed during my time as forum moderator.
I'm pleased to see that in this year's stack overflow 2022 survey Phoenix is the most loved web framework; I suspect this has a lot to do with LiveView which was introduced in 2018. In my judgement the Erlang VM gives LiveView a big technical advantage over the later competitors Laravel Livewire and Rails Hotwire - but those have larger communities and ecosystems.
But this style of web application (server based SPA) is subject to some very specific constraints in the wider range of all possible web application styles.
Patterns for Building JavaScript Websites in 2022
Ryan Carniato for This is Learning ・ Jun 8 ・ 9 min read
Though Phoenix is also a great platform for API servers and "regular" server routed websites with EEx templates but competition in that space is even fiercer.
Elixir and Erlang in my view are undervalued especially given that the Erlang VM is a lot more prevalent than people realize.
"60% of the world mobile traffic is going through Erlang" (24m48s)
That said the mainstream inclination is to go the K8s, Docker, Go-lang route.
What is easier to scale, Go with Docker and Kubernetes or Erlang / Elixir + OTP?
If you have any more questions why not ask them here?
Though for more up to date information I'd just sign up at elixirforum.com and ask away there. The community has always been very welcoming. And many members are on slack as well.
Hey Patrick! I'm glad you're enjoying it so far - I work at a consultancy primarily focussed on Elixir and a lot of us are also Rubyists at heart, and we can definitely see the parallels. If you enjoyed Rails, Phoenix and LiveView are similar, but with some of the conventions stripped out. They can be a lot to get your head around, but are so, so pleasant to work with once you understand how it all hangs together :)
elixirforum.com/ is the OG
I found some more communities
Opensource social network using elixir (PETAL) bonfirenetworks.org/