Elixir: Generating a new Application with Mix - [003]

Mix is the de-facto standard tool when it comes to working with elixir. In this episode we'll get familiar with it by generating a project.

There is a couple ways to generate a project in elixir.

  • Library - mix new [project-name]
  • Application - mix new [project-name] --sup
The extra --sup flag indicated that we would like to generate an application with a supervision tree.

The BEAM Vm

To understand what the different between a library and an application we need to understand what the BEAM VM is. Essentially it's the VM that runs your compiled elixir / erlang code. That's right elixir / erlang are compiled languages that get compiled down to beam bytecode.

The BEAM Vm is like a stripped down version of an OS. It can manage processes and has it's own scheduler. This is the reason why elixir can leverage multi-core out of the box. So essentially applications and supervision trees are programmable processes that run inside of the BEAM Vm.

Hello World Project

We will use Botiful as the name of the application. Once we generate our project we can run it in the console using.

iex -S mix

This will boot our application. Let's execute some elixir code.

Botiful.hello():world

Supervision Tree

We'll talk more about the supervision tree a little down the line however if you're curios about what it looks like you can try typing

:observer.start()

This will open the process observer which you can inspect the different processes, just like top in linux!