Chapter 1 - Introduction
- 1.Dynamic – Elixir lets you write your code without having to specify the types (e.g., int, string, float, etc…) for all your variables which saves you time and allows you to iterate faster. This is similar to what you do in Python.
- 2.Functional – This style of programming is focused on grouping your code into functions that can be reused to create data transformation pipelines.
- 3.Scalable – “All Elixir code runs inside lightweight threads of execution (called processes) that are isolated and exchange information via messages.” It is not uncommon to have thousands of processes running at the same time. In short, more processes equals doing more tasks in parallel. This is a big difference to the typical single-threaded languages (that most people use) becuase they work in series.
- 4.Maintainable – Elixir guarantees data immutability, meaning it never changes. This guarantees that your functions will always return the same result given the same input. As obvious as it sounds, this is not always the case in languages that allow side effects. Combine that with the functional approach to writing software, and you have a recipe for code that is short, concise and just works. It’s refreshing to know that 2 + 2 will always equal 4.
- 1.Is Functional In Nature - If you remember back to your Algebra days, you came across the concept of a function. That function would do some transformation (typically to
x) and save it to a variable (typically
y) and looked something like this
y=f(x). What makes functional languages special is that given the same input, the output will always be the same. This is not the case with many programming languages.
- 2.Provides Clarity in Transforming Data - Elixir uses functions to take data and transform it through multiple steps for a desired outcome, model, etc.. This is what makes the Tidyverse for R so wonderful. Imagine a whole language that works like the Tidyverse!
- 3.Is A Tool Worth Using - According to the Stack Overflow 2022 survey below, Elixir is the 2nd most loved language with the most loved web framework. The main point here is that the people using Elixir actually enjoy working in it.
StackOverflow 2022 Survey Results
NoteElixir already has a production-ready web framework named Phoenix.
- Do you want to use your model in your website? Done.
- Do you want to deploy your model results as an API for others to consume? No problem.The cool part is, Phoenix is the most loved web framework according to the Stack Overflow 2022 Survey (shown below).
- 4.Provides A Clear Path to Production - Building models on your machine is rewarding, but what about when you are ready to go live? How much additional effort and complexity is needed to turn your Python or R code into something that is production ready?
How will you handle:
- Background Jobs?
- Crash Recovery?
- Long-Running Requests?
- Low Latency App State?
With Elixir, you will not need additional technologies to handle these real-world requirements. If you are new to programming, why burden yourself with additional headaches of learning how to share your work with others when these problems have already been solved in Elixir?
The Elixir community has developed an interactive computational notebook wrapped around the Elixir language called Livebook. We will be using Livebook to run all the code found in this book. For those who may be new to Elixir, Livebook serves as a great vehicle to learning the Elixir language. You can learn more about Livebook in Chapter XX.
There are 3 ways to get up and going with Elixir and Livebook.
The easiest way to get up and going is heading over to Livebook.dev and selecting the Mac or Windows option which will download the Elixir language and Livebook software to your computer. Once downloaded, simply install Livebook, and you’re up and running. That’s it!
If you prefer to work in the cloud, select the Fly.io option. This requires setting up an account and a few odds and ends. You should be up and running in under 5 minutes. You may need to pay for compute usage based on the amount of RAM needed for you analysis.
If you’d like to manually install Livebook, then you’ll need to install:
- Step 1 - Erlang
- Step 2 - Elixir
- Step 3 - Run Escript
The packages that you will learn in this book are:
Now you are ready to go!