Learning Elixir: Alias, Import, Require and Use

I’ve published a new article in my Elixir learning series on dev.to exploring the module directives — alias, import, require, and use — the four tools that control how names from other modules become available in ours.

The article covers:

  • The difference between the three lexically scoped directives and the use macro
  • Using alias to shorten module names, including the :as option, grouping with braces, and nested aliases
  • Bringing functions into scope with import, with only:, except:, and filtering functions vs macros
  • How lexical scope works inside functions and what happens when imports collide
  • Opting into macros with require, using the classic Integer.is_even/1 example
  • use as an extension point and how it expands to require plus a using/1 callback
  • Putting all three directives together in a realistic module
  • Practical guidelines for when to reach for each tool — and why alias often beats import

With complete working examples you can copy into IEx, you’ll learn how these directives shape the namespace of a module and make the origin of every name clear — a big step toward reading and organizing Elixir code confidently.

Check it out: