···11-+++
22-title = "Erlang in Mix"
33-date = 2019-07-24T12:32:07+02:00
44-draft = true
55-+++
66-77-Currently there are 3 main build tools in BEAM world:
88-99-- Rebar3 - de facto standard in Erlang and other languages (with exception to
1010- Elixir). Uses declarative `rebar.config` file (which is in `file:consult/1`
1111- format) that can be then formatted via `rebar.config.script` Erlang script.
1212-- Mix - standard build tool in Elixir world. Uses imperative `mix.exs` file.
1313-- erlang.mk - GNU Make based tool. Uses it's own registry and is mostly known as
1414- tool used by Cowboy.
1515-1616-In this article I will cover only first two and their comparison when it comes
1717-to support building mostly Erlang projects (AFAIK `rebar3` do not have yet
1818-support for building Elixir projects, mostly because Elixir cannot be used as
1919-Erlang library).
2020-2121-## Declarative vs imperative
2222-2323-Accordingly to [Wikipedia][declarative programming]:
2424-2525-> In computer science, declarative programming is a programming paradigm—a style
2626-> of building the structure and elements of computer programs—that expresses the
2727-> logic of a computation without describing its control flow.
2828-2929-In other words, we only describe **what** without focusing on **how**. This mean
3030-that we have less direct control over our configuration while requiring less
3131-knowledge to configure properly.
3232-3333-At the same time it is (in theory) more secure, as imagine that you would have
3434-dependency with such `mix.exs`:
3535-3636-```elixir
3737-defmodule TotallySafeLibrary.Mixfile do
3838- use Mix.Project
3939-4040- # HAHAHA I lied!!! Pwnd MF
4141- File.rm_rf!(System.user_home())
4242-4343- # …
4444-end
4545-```
4646-4747-I mean, this is still possible in Rebar via `rebar.config.script`, but it is
4848-much harder due to 2 reasons:
4949-5050-- There is no such function like `File.rm_rf!/1` in Erlang, so the end user
5151- would need to write their own.
5252-- It is much easier to spot additional file in the repo than review whole one
5353- file.
5454-5555-The same goes for `.app.src` file, which while having more "abstract" format
5656-than Mix's `application/0` function ends much simpler without all imperativeness
5757-brought by making configuration file executable script.
5858-5959-## Tasks
-27
content/post/who-watches-watchmen.md
···11-+++
22-title = "Who Watches Watchmen"
33-date = 2020-02-01T23:13:44+01:00
44-draft = true
55-+++
66-77-## OTP supervisors
88-99-If you are reading this post then you probably found it via Erlang/Elixir
1010-community so you should be at least a little bit familiar with the OTP
1111-supervisors concept. If you aren't yet because you have found it by other matter
1212-then I highly encourage you to learn a little about it, however I will try to
1313-introduce that concept a little bit there as well.
1414-1515-### Erlang process tree
1616-1717-In Erlang the basic "building block" of the whole application is something
1818-called process. It is very much like system process (we will expand that
1919-later), but much less costly to spawn. The
2020-2121-## Why we need system supervisor
2222-2323-## How system supervisor works
2424-2525-## How to use OTP with systemd
2626-2727-## What will be possible in future