Oboe
No history yet

Elixir language

Welcome! I'm excited to help you dive into Elixir.

Before we jump into the code, it helps to know what kind of projects you've worked on. To help me tailor our session, could you tell me a little bit about your programming experience, specifically if you have used any functional programming languages before?

I have experience with OOP (like Python, JS, or Java) but not functional programming.

It is great to have you here! Transitioning from object-oriented programming to functional programming is an exciting shift in mindset, and Elixir is a fantastic language to bridge that gap.

What is Elixir?

At its core, Elixir is a dynamic, language designed for building scalable, high-concurrency, and maintainable applications. If you are coming from Python or JavaScript, you might be used to objects, mutable states, and class hierarchies. Elixir discards these in favor of immutable data and pure functions. Instead of modifying an object's state in place, you pass data through a series of transformations, like an assembly line.

The Secret Weapon: The BEAM Virtual Machine

Elixir does not run directly on your hardware. It compiles to bytecode that runs on the , the Erlang Virtual Machine. Erlang was built by Ericsson in the 1980s to run massive telecommunication switches. It was designed from day one to handle millions of simultaneous connections and to stay up no matter what—even if some hardware fails. By running on the BEAM, Elixir inherits three superpowers:
  1. Massive Concurrency: It can run millions of isolated processes simultaneously on a single machine without breaking a sweat.
  2. Fault Tolerance: If a process crashes, it doesn't bring down the whole application. Elixir uses "supervisors" to automatically restart failed parts of your app to a known safe state.
  3. Low Latency: The virtual machine ensures that no single heavy process can hoard the CPU, keeping your application highly responsive under heavy loads.

The Design Philosophy

Elixir was created in 2011 by José Valim. He loved the performance and resilience of Erlang, but wanted a modern language with high developer productivity. To achieve this, he designed Elixir's syntax to feel clean and friendly (strongly inspired by Ruby), while pulling powerful metaprogramming capabilities from Clojure, and keeping the rock-solid runtime characteristics of Erlang.

Let's continue to the interactive shell (IEx)

Let's dive straight into the interactive shell, known as . It is the playground where you will write, test, and instantly run Elixir code without having to set up a massive project structure first.

Starting the Shell

To fire up the shell, you simply open your terminal and type iex. If you are on Windows using PowerShell, you might need to run iex.bat instead, because iex is a built-in alias in PowerShell. Once loaded, you will see a welcoming prompt like this:
Interactive Elixir (1.20.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> 
The iex(1)> prompt is waiting for you to type some Elixir code. Let's try typing a simple mathematical expression to see how it evaluates things instantly.
iex(1)> 40 + 2
42