···
2
-
title = "Erlang in Mix"
3
-
date = 2019-07-24T12:32:07+02:00
7
-
Currently there are 3 main build tools in BEAM world:
9
-
- Rebar3 - de facto standard in Erlang and other languages (with exception to
10
-
Elixir). Uses declarative `rebar.config` file (which is in `file:consult/1`
11
-
format) that can be then formatted via `rebar.config.script` Erlang script.
12
-
- Mix - standard build tool in Elixir world. Uses imperative `mix.exs` file.
13
-
- erlang.mk - GNU Make based tool. Uses it's own registry and is mostly known as
14
-
tool used by Cowboy.
16
-
In this article I will cover only first two and their comparison when it comes
17
-
to support building mostly Erlang projects (AFAIK `rebar3` do not have yet
18
-
support for building Elixir projects, mostly because Elixir cannot be used as
21
-
## Declarative vs imperative
23
-
Accordingly to [Wikipedia][declarative programming]:
25
-
> In computer science, declarative programming is a programming paradigm—a style
26
-
> of building the structure and elements of computer programs—that expresses the
27
-
> logic of a computation without describing its control flow.
29
-
In other words, we only describe **what** without focusing on **how**. This mean
30
-
that we have less direct control over our configuration while requiring less
31
-
knowledge to configure properly.
33
-
At the same time it is (in theory) more secure, as imagine that you would have
34
-
dependency with such `mix.exs`:
37
-
defmodule TotallySafeLibrary.Mixfile do
40
-
# HAHAHA I lied!!! Pwnd MF
41
-
File.rm_rf!(System.user_home())
47
-
I mean, this is still possible in Rebar via `rebar.config.script`, but it is
48
-
much harder due to 2 reasons:
50
-
- There is no such function like `File.rm_rf!/1` in Erlang, so the end user
51
-
would need to write their own.
52
-
- It is much easier to spot additional file in the repo than review whole one
55
-
The same goes for `.app.src` file, which while having more "abstract" format
56
-
than Mix's `application/0` function ends much simpler without all imperativeness
57
-
brought by making configuration file executable script.