Lib vs src

why mix creates lib folder instead of src, I noticed that src is usually used, and think it is more convenient?

Actually multiple folders at root have source files in them - test and lib at a minimum, usually you have code in config too. So calling one folder “src” might be misleading. I do not think a folder with the letters “s-r-c” is inherently more convenient than “l-i-b” - what is convenient is following the conventions of the language community for the language you are presently using, so that is what mix does. Mix also establishes those conventions.

If I had to guess at the history behind this, “lib” is commonly used in Ruby, which has no notion of source files being separate from compiled object files, since all files are interpreted when the VM starts up.

1 Like

If I remember correctly, it was due to Erlang’s convention to keep source files in src, so to make Elixir sources distict, the team decided to use lib.

At least in 2013 José said that if you put Erlang sources in src, Mix would compile it too (I don’t know if it still stands):

Quoting the answer:

Mix can compile erlang files if you put them in src.

The relevant documentation:

For Elixir:

$ mix help compile.elixir

(...)

## Configuration

  • :elixirc_paths - directories to find source files. Defaults to ["lib"].

For Erlang:

$ mix help compile.erlang

(...)

## Configuration

  • :erlc_paths - directories to find source files. Defaults to ["src"].

These defaults can be overwritten by specifying these configuration options in your mix.exs.

5 Likes