What annotation attributes should Elixir developers know?

What attributes are common for developers to know and use in professional Elixir development? For example, there is:

  • @moduledoc - provides documentation for the current module.
  • @doc - provides documentation for the function or macro that follows the attribute.
  • @behaviour - (notice the British spelling) used for specifying an OTP or user-defined behaviour.
  • @before_compile - provides a hook that will be invoked before the module is compiled. This makes it possible to inject functions inside the module exactly before compilation.
  • @callback - used to a define a behaviour module, expecting a function name and typespec
  • @vsn - used by the code reloading mechanism in the Erlang VM to check if a module has been updated
  • @impl - used to identify a function as implementing a callback function for a particular behaviour module
  • @spec - defines a typespec for a given function

What other attributes are we missing?
Edit: full-disclosure, I want to update the docs with a full list of these. They’re good to know :thumbsup:


Maybe @type and @typep

1 Like

You have forgotten @opaque which is for types as well.

In generall, you can look up all “official” module attributes which are “reserved” in the documentation of the Module-module :wink:

Maybe @enforce_keys, but it is not for annotation