These Modern Programming Languages Will Make You Suffer
By: Ilya Suzdalnitski
Tags: JavaScript, Python, Programming, Software Development, Web Development

Elixir

Elixir probably is the most popular functional programming language in the world. Just like ReasonML, Elixir is not really a new language. Instead, Elixir builds upon more than three decades of Erlang’s success.

Elixir is Go’s functional cousin. Just like Go, Elixir was designed from the ground up for concurrency to take advantage of multiple processor cores.

Unlike some other functional languages, Elixir is very pragmatic. It’s focused on getting results. You won’t find long academic discussions in the Elixir community. The Elixir Forum is full of solutions to actual, real-world problems, and the community is very friendly to beginners.

Language family: ML.

👍 👍 Ecosystem

What really makes Elixir shine is its ecosystem. In most other languages there’s the language and there’s the ecosystem — two separate things. In Elixir, the core frameworks in the ecosystem are being developed by the core Elixir team. José Valim, the creator of Elixir is also the main contributor in Phoenix and Ecto — the super cool libraries in the Elixir ecosystem.

In most other languages there’re many different libraries focused on the same task — many different web servers, many different ORMs, etc. In Elixir, the development efforts are really focused on the core few libraries, which results in outstanding library quality.

The documentation of Elixir libraries is very good, with plenty of examples. Unlike some other languages, the standard library is also very well documented.

👍 Phoenix framework

The slogan of the Phoenix framework is “Phoenix just feels right”. Unlike frameworks in other languages, Phoenix has a lot of functionality built-in. Out of the box, it supports WebSockets, routing, HTML templating language, internationalization, JSON encoders/decoders, seamless ORM integration(Ecto), sessions, SPA toolkit, and a lot more.

Phoenix framework is known for its great performance, being able to handle millions of simultaneous connections on a single machine.

👍 Fullstack Elixir

The Phoenix framework has recently introduced LiveView, which allows building rich realtime web interfaces right within Elixir (think Single-Page Applications). No JavaScript needed, no React!

LiveView even takes care of synchronizing the client and server state, which means that we don’t have to worry about developing and maintaining a REST/GraphQL API.

👍 Data processing

Elixir can be a solid alternative to Python for a lot of tasks related to data-processing. Having built a web scraper in both Python and Elixir, Elixir is hands down a much better language and ecosystem for the task.

Tools like Broadway allow building data ingestion/data processing pipelines in Elixir.

👌 Type System

In my opinion, the lack of proper static typing is the biggest drawback of Elixir. While Elixir isn’t statically typed, the compiler (along with dialyzer) will report a lot of errors at compile-time. This goes a long way over dynamically typed languages (like JavaScript, Python and Clojure).

👍 Speed

Elixir compiler is multi-threaded and offers blazing fast compilation speeds. Unlike Java Virtual Machine, the Erlang VM is fast to start. The runtime performance is very good for Elixir’s use cases.

👍👍 Reliability

Elixir builds on top of Erlang, which was used for over 30 years to build the most reliable software in the world. Some programs running on top of the Erlang VM have been able to achieve 99.9999999% reliability. No other platform in the world can boast the same level of reliability.

👍 👍 Concurrency

Most other programming languages have not been designed for concurrency. This means that writing code that makes use of multiple threads/processor cores is far from trivial. Other programming languages make use of threads that execute parallel code (and shared memory, that the threads read from/write to). Such approach typically is error-prone, prone to deadlocks, and causes exponential increases in complexity.

Elixir builds on top of Erlang, which is known for its great concurrency features, and takes an entirely different approach to concurrency, called the actor model. Within this model, nothing is shared between the processes(actors). Each process maintains its own internal state, and the only way to communicate between the various processes is by sending messages.

By the way, the actor model really is OOP as first intended by its creator, Alan Kay, where nothing is shared, and objects only communicate by passing messages.

Let’s draw a quick comparison between Elixir, and its imperative cousin Go. Unlike Go, Elixir was designed from the ground up for fault tolerance. Whenever a goroutine crashes, the entire Go program goes down. In Elixir, whenever a process dies, only that single process dies, without affecting the rest of the program. Even better, the failed process will get restarted automatically by its supervisor. This allows the failed process to retry the operation that has failed.

Elixir processes are also very lightweight, one can easily spin hundreds of thousands of processes on a single machine.

👍 👍 Scaling

Let’s draw another comparison with Go. Concurrency in both Go and Elixir makes use of message passing between concurrent processes. Go programs will run faster on the first machine since Go compiles to native code.

However, once you start scaling beyond the first machine, Go programs start losing. Why? Because Elixir was designed from the ground up to run on multiple machines. The Erlang VM that Elixir runs on top of really shines when it comes to distribution and scaling. It seamlessly takes care of many tedious things like clustering, RPC functionality, and networking.

In a sense, the Erlang VM was doing microservices decades before microservices became a thing. Every process can be thought of as a microservice — just like microservices, processes are independent from one another. It’s not uncommon for processes to run across multiple machines, with communication mechanism built into the language.

Microservices without the complexity of Kubernetes? Check. That’s what Elixir was really designed for.

👍 Error handling

Elixir takes a very unique approach to error handling. While pure functional languages (Haskell/Elm) are designed to minimize the probability of errors, Elixir assumes that errors will inevitably happen.

Throwing exceptions is fine in Elixir, while catching exceptions generally is discouraged. Instead, the process supervisor will restart the failed process automatically to keep the program running.

👌 Learning effort

Elixir is a simple language that one can pick up in a month or two. What makes the learning somewhat harder is OTP.

OTP is the killer feature of Elixir. OTP is a set of tools and libraries from Erlang that Elixir builds upon. It is the secret sauce that significantly simplifies building concurrent and distributed programs.

While Elixir itself is pretty simple, wrapping one’s head around OTP can take some time — it certainly did for me.

👍 Learning resources

Being the most popular functional programming language, Elixir has a wealth of learning resources. There are a dozen amazing Elixir books on the Pragmatic Programmers. The learning resources almost always are super friendly to beginners.

👍 Pattern matching

Elixir has great pattern matching support.

👎 Crunching numbers

Elixir doesn’t handle computationally-intensive tasks well. A compile-to-native language should be chosen instead for such tasks (Go/Rust are good options).

Ok, what’s the deal with Erlang?

For all intents and purposes, Elixir and Erlang are identical under the hood. Erlang is a powerful language with a weird syntax. Elixir can be thought of as a nicer and more modern syntax for Erlang (along with a very nice ecosystem and community).

Verdict

Elixir probably is the most mature of all functional languages. It also runs on top of a virtual machine made for functional programming. It was designed for concurrency from the ground up and is a perfect fit for the modern era of multicore processors.

Watch the short Elixir Documentary to learn more.

Awards

Elixir receives two awards.

Its resiliency, functional-first approach, and amazing ecosystem makes it the Best Language for Building Web APIs.

OTP and the actor model make Elixir the Best Language for Building Concurrent and Distributed Software. Unlike its imperative cousin Go, software written in Elixir can scale horizontally to thousands of servers and comes with fault tolerance out of the box.