Elixir

Elixir

Introduction to Elixir

Elixir is a functional, dynamically typed language that is built on top of Erlang’s VM and compiles down to Erlang bytecode.

Since its release in 2011, it has become one of the most loved languages, according to the Stack Overflow Developer Survey. And for good reason. Elixir applications are scalable, very reliable, and the syntax is also quite nice.

While the language has made headway in highly concurrent web applications, some of our readers might not yet be familiar with it. In this article, we will give a brief introduction to what Elixir is and why one would use it for a software project in contrast to technologies like Java, Ruby, and others.

Main features of Elixir

The Elixir programming language wraps functional programming with immutable state and an actor-based approach to concurrency in a tidy, modern syntax. And it runs on the industrial-strength, high-performance, distributed Erlang VM. But what does all that mean? — Dave Thomas, Programming Elixir

  • Elixir is built on top of the Erlang VM. Elixir has access to all the concurrency tools that Erlang has access to, making it one of the most powerful modern languages for building scalable, distributed systems.
  • Elixir has Ruby-like syntax. If you have already programmed in Ruby, the syntax of Elixir will feel very familiar. Ruby is one of the most concise and productivity-oriented languages out there, but it is lacking in performance and concurrency. Erlang VM solves both of these problems, and, therefore, Elixir is the best of both worlds.
  • Elixir is functional. While Elixir and Erlang could be characterized as being in a group of their own (they are both process-oriented), Elixir also has all the constructs you expect from modern FP languages. In particular, immutable data structures help concurrency quite a lot, and pattern matching is great for writing declarative code.
  • Elixir has dynamic typing. Elixir has dynamic typing in contrast to other functional languages like Haskell and Scala. This means that types are checked in run-time, not during compilation. While this can be a downside when building critical systems, it also increases development speed for simple web applications. Static types can be introduced in Elixir through typespecs.

Benefits of Elixir

BEAM

Elixir is built on top of BEAM, the Erlang VM, and it shares the same abstractions that have made Erlang one of the best choices for concurrent, high-volume applications.

With Erlang, Elixir shares these three characteristics:

  • Concurrency. Elixir uses lightweight threads of execution (called processes). These are isolated, run across all CPUs, and communicate through messages. Together with the immutability of data that comes from the functional nature of the language, this makes it less hard to write concurrent programs in Elixir.
  • Scalability. These same processes allow us to scale systems easily, either horizontally (adding more machines to the cluster) or vertically (using the available resources of the machine more efficiently).
  • Reliability. Elixir and Erlang have a unique approach to fault-tolerance. While things sometimes inevitably fail in production, lightweight processes can be quickly restarted by the supervisor system. This deals with most bugs that are not due to serious faults in software development.

From Erlang, Elixir also gets the Open Telecom Platform. OTP is a part of Erlang’s standard library that was used to achieve fault-tolerance in telecom systems, but its usage nowadays is much wider – one can use it for basically any type of concurrent programming.

Compared to conventional solutions, OTP gives a great foundation so that the developer can spend time on implementing the actual business logic. With other languages, a lot of time is spent on plumbing.

Functional programming

Besides, Elixir is very much a functional programming language.

Functional programming is a programming paradigm that treats programs like evaluations of mathematical functions and avoids things like mutable data and changing state.

In contrast to mainstream programming languages like Java or Python, Elixir code is structured in functions and modules (groups of functions) instead of objects and classes. In addition, all the data types are immutable. For example, calling a function on a variable will produce a new variable, not change the variable in place.

Functional programming supports and takes advantage of things like pattern matching, higher-order functions, and declarative style of writing code, and that comes with multiple benefits:

  • better maintainability;
  • clearer testing and debugging;
  • easier handling of concurrent programs;
  • high-level abstractions that make code simpler to write and understand.

For more info on the benefits of functional programming, check out our Introduction to Functional Programming.

Phoenix

If you want to use the best web framework in the world, you will have to use Elixir.

Phoenix is as easy to use as any of your regular MVC web frameworks (like Rails and Django), but it is also backed up by the BEAM. It enables one to efficiently churn out web apps while not compromising on either speed or maintainability.

Turns out, the lightweight processes of Elixir/Erlang are great for solving problems of concurrency and scalability in web services. While Phoenix Channels can achieve 2 million websocket connections on a single box, the capacity can be multiplied by distributing the traffic to more nodes.

It has downsides too, though. The ecosystem of Phoenix and Elixir is not as mature as for Ruby on Rails or Python’s Django, so one might run into the problem where “not all batteries are included”. But all in all, the benefits outweigh the costs.


To view or add a comment, sign in

More articles by Anjali Kumari

  • Blockchain Technology

    For all you’ve probably heard about Bitcoin, Ethereum, and other cryptocurrencies lately, many financial experts say…

  • Apache Airflow
  • STLC
  • DBI SQL
  • Azure Data Factory
  • Backend Developer

    What Is The Role Of A Back-End Developer The back-end developers generally work along with the front-end developers as…

  • DAX

    What is DAX DAX stands for Data Analysis Expressions, it is language developed by Microsoft to interact with data in a…

  • GitHub

    GitHub is a code hosting platform for version control and collaboration. It lets you and others work together on…

  • JIRA

    A Jira 'issue' refers to a single work item of any type or size that is tracked from creation to completion. For…

  • Data Repository

    Data Repository: Types, Challenges, and Best Practice The importance of data is growing as everyone uses data to make…

Insights from the community

Others also viewed

Explore topics