What's the difference between `use` and `#before_compile`?
What's the difference between use and #before_compile? Both can be used to inject some code in to current module.
One main difference is that the code in __using__ is called and return value injected as soon as you call use within a module, while __before_compile__ is called and the return value injected after all the code directly inside the module is executed, just before the module is compiled. A simple program to demonstrate the difference: defmodule When do defmacro __using__(_) do IO.inspect :using __CALLER__.module |> Module.definitions_in |> IO.inspect quote do end end defmacro __before_compile__(_) do IO.inspect :before_compile __CALLER__.module |> Module.definitions_in |> IO.inspect quote do end end end defmodule Main do #before_compile When use When IO.puts "added `#before_compile` and `use`" def add(x, y), do: x + y end Output: :using  added `#before_compile` and `use` :before_compile [add: 2] ExUnit uses #before_compile to define a function that returns all the tests to make it possible for the ExUnit runner to get and run all the tests.
How to define functions based on attribute to elixir?
Remove a const qualifier from a variable in D
Meta-modeling crud FROM/JOIN/WHERE statement fragments for higher-level analysis
Elixir: eval'ing code in module context using Code.eval_quoted/3
What is Declarative Meta-Programming?
Reconsolidate protocols in Elixir 1.2 or higher
Inserting an AST into a quote do end block without unquoting it
Transform quoted elixir code to a code string
Pattern matching benchmarking : Compiletime lookup vs Runtime lookup in D
Meta construction capabilities?
How to manipulate the value of variables based on an array of symbols in Julia?
Multiple #:build macros
Julia automatically generate functions and export them
Dealing with end keyword in macros for array indices
Implementation of AnyMap and runtime overhead of `struct Port(u32);`
Can function application be overriden with Macro in Elixir?