Introduction to Elixir (Part 1)

May 14th, 2021
#Elixir #Backend #Quickstart #Series #Introduction to Elixir

elixir language image

Elixir is a dynamic, functional language for building scalable and maintainable applications.

https://elixir-lang.org

Elixir is now one of the most loved languages since its release in the year 2011 — Stack Overflow Developer Survey. Elixir has been used to build very reliable and scalable applications with its powerful sets of features which we will be looking at together in this series of introductory articles.

While the language has made strides in highly concurrent applications, it's obvious that most developers still don't have an idea about its capabilities. So in this introductory series, we will be looking at features it provides to build stable software while improving the developer experience.

What is Erlang?

Every discussion about Elixir always refers to Erlang — Do you know why?.

Erlang is an old language that was created in the 1980s. Erlang is battle-tested for highly stable and concurrent applications like the phone switching problem it was created for, which it did almost perfectly with incredible uptime.

Considering its main selling point, fault-tolerance, José Valim created Elixir to make this goody easily accessible to the community.

While Erlang and Elixir are both still used widely in their respective fields, Elixir is much more popular and gaining popularity due to its low learning curve with its Ruby-like syntax and expressiveness.

Core Features

Functional programming

Functional programming is a programming paradigm that is of the notion that software is built by composing pure functions, avoiding shared state, mutable data, and side effects while being declarative. Contrast with object-oriented programming, where application state is usually shared and colocated with methods in objects.

The Elixir programming language wraps functional programming with an immutable state and an actor-based approach to concurrency in a tidy, modern syntax.

— Dave Thomas, Programming Elixir

Functional code tends to be shorter, more predictable, and easier to test than imperative or object-oriented code — but if you’re unfamiliar with it and the common patterns associated with it, functional code can also seem a lot denser, and the related literature can be fortress-like to newcomers.

Elixir comes with very beautiful features like, function guards, pattern matching, which allows developers to write very short, declarative, and concise functions.

Dynamic Typing

Elixir has dynamic typing in contrast to other functional languages like Haskell and Scala. This means that types are not checked during compilation until runtime when the application is running or executed. This has its benefits as it increases development speed for simple applications. But for mission-critical apps, one can leverage typespecs to improve typecheck, and you can also make use of tools like credo for improved static analysis.

Scalability

All Elixir code runs in lightweight threads called Processes that are isolated and can only communicate to other processes using messages.

Elixir leverages the Erlang VM, known for running low-latency, distributed, and fault-tolerant systems. Elixir is successfully used in web development, embedded software, data ingestion, and multimedia processing, across a wide range of industries.

https://elixir-lang.org

Due to its lightweight attribute, it's very uncommon to not have hundreds of thousands of processes running concurrently on the same machine while using the machine resources as efficiently as possible — vertical scaling.

Processes are also able to communicate with other processes running on different machines as long as they are on the same network. This capability makes Elixir suitable for distributed systems.

Erlang Compatible

Earlier, it was mentioned that making the goodies provided by Erlang easily accessible to the developers is one of the reasons why Elixir was created.

Elixir runs on the Erlang VM called Beam, giving the developers access to the ecosystem and that's one of the reasons why you can invoke Erlang libraries that are production tested in your Elixir application without hassles.

And Erlang has proven to be production-ready for highly concurrent applications when you take look at companies that use it, WhatsApp, Discord, Heroku, Spotify and many other companies.

Conclusion

Remember this is a series of introductory articles about Elixir and that's why there will be more posts coming up to shed more light on the language features so that you can have a good understanding of them. I hope you liked this introductory post, do not hesitate to follow me on Twitter and Linkedin so that you get notified when the other parts to this series are posted.

In the other parts of this series, we will be looking at Data Types, Pattern Matching, Functions & Modules, and a brief intro to Processes. During the publishing of the concluding parts, we will get to see why the highlighted core features are of great benefit to building very fault-tolerant and concurrent applications.

Elixir Data Types (Part 2)
next

Made with 💙 © 2020 Atanda Rasheed