3. Fast and Confident Refactoring
Refactoring—making significant changes to the existing code base, sometimes without changing the code’s external behavior—is often a “dangerous” part of development because it’s all too easy to break something. In functional, immutable languages such as Elixir, however, refactoring and testing are much simpler. You can make sweeping changes without fear of accidentally making things worse.
At Very, we practicetest-driven development (TDD). All tests are written before writing a single line of code. Once these tests (expectedly) fail, you write the code that makes them pass. This process ensures that you have tests for your code, which makes refactoring easy and fast.
4. Process-Based Language
Being able to parallelize workloads and use multiple processes is native to Elixir, a trait that it inherits from Erlang.
Normally, code that is single-threaded in languages such as Java and not meant to handle high loads will need to be rewritten once the service starts to scale. In Elixir, you’ll need to make a few changes here and there, but much less than in other programming languages.
Elixir makes use of thePhoenix framework, a web framework written in Elixir for Elixir developers. With Phoenix, each request is given its own process that’s extremely fast with a low memory footprint. This allows you to create thousands of processes quickly without worrying about their impact on performance.
5. Parallelism vs. Concurrency
Parallel systems can have latency and responsiveness issues because a single task will require a lot of computing power. In Elixir, however, the process scheduler will preemptively shift control to a different process. Even when your application is under an extreme load, a single slow process can’t hinder the entire system.
As a result, Elixir almost guarantees low latency for your application. This is highly important for modern web applications that need to provide a consistent experience to all visitors.
With many programming languages, a bug in one process will cause your entire application to crash and fail. In Elixir, however, failure is contained to a single process. If one user in a web application makes a request with a bug in it, that process will crash but all other users will remain connected. Elixir enables you to limit the “blast radius” when a process fails.
When Should You Use Elixir?
First, let’s discuss when you should not use Elixir. Systems that are CPU-bound by an inherently sequential task are not a good match for Elixir. If an individual task is difficult to compute and requires serious CPU power, such as advanced mathematical problems, then you should look to another programming language.
However, nearly any use case that is not CPU-bound, and not inherently sequential, is probably a good fit for Elixir. In particular, Elixir works well for systems that are high-traffic, have many connections, or are I/O bound. This description applies to many modern use cases: chat backends (e.g. Facebook Messenger and Whatsapp), web servers, APIs, web applications, and more.
Elixir and IoT
Low-level programming languages such as C have traditionally been the preferred choice for IoT (Internet of Things) development. Although these low-level languages are powerful and give you a lot of control, they’re also difficult to work with and easy to fail.
Elixir can also be used in embedded IoT firmware using the Nerves framework. As a higher-level language, Elixir allows you to write high-quality code more quickly. Here at Very, for example, we recently used Elixir to build an IoT self-serve beer kioskpowered by facial recognition. Given our experience with numerous clients, we see a convincing case for using Elixir and Nerves in the development process for IoT applications.
Elixir is a powerful and dynamic programming language that builds on the strength of predecessors such as Ruby and Erlang. It’s an excellent choice for any situation where performance and scalability are at a premium, including web applications and IoT development projects.