Why would I choose Elixir as a general purpose programming language?

Yes, there just is nothing preventing you from doing it all the time. This makes certain things a lot more easy (such as doing IO and working with randomly generated data). This means that Elixir has a lot less steep learning curve than e.g. Haskell, at the expense of some flexibility that Haskell’s pure abstraction layers can provide. In Elixir, functional programming is a means while in Haskell it is an (the?) end itself.

Working with state is a lot harder in a pure language, because this involves Monads, which are considered one of the harder to understand concepts, if only because they are so abstract that it is hard to write a guide about them that works for everyone. I would definitely consider it to be one of the most important tools to understand for programmers especially because they are so generalizeable, but this definitely takes a lot of time and effort.

Writing code that happens to be pure is the easiest to reason about and, at least in my opinion, usually the most idiomatic way to solve a problem. If you want to keep as closely to the ‘pure functional’ ideal as possible, just don’t perform any side-effects in your functions, except at the outermost layer(s).

About using Elixir’s concurrency model: You don’t need to work with it, nor understand it, when starting out with Elixir. At some point you will start writing code where it makes sense to split certain parts of the computation or state-keeping off to a separate process so multiple things can happen at the same time, but it is important to never forget that the main unit of code organization in Elixir is not a Process, but a Module.

So: You’ll cross that bridge when you come to it. For many simple tasks, you can use Elixir perfectly without using the concurrency model directly. The code you write will still be faster than interpreted languages (Ruby, Python, …) because Elixir compiles to bytecode, and more readable / easier to understand than when using a systems language like C, C++, Rust. Yes, e.g. Haskell might compile to even faster, native, code, but learning it comes with a steeper learning curve and the documentation is not as good/readable/extensive/accessible as Elixir’s (I think these arguments can also be made for OCaml, but I’ll refrain from doing so because I have no personal experience with it, and @OvermindDL1 might lynch me :sweat_smile:).

Switching to a functional language will most importantly give you the benefit of referential transparency which makes your code a lot easier to maintain than object-oriented or imperative languages.

4 Likes