# Runtime dependency between modules cause by function definition

**URL:** <https://forum.elixirforum.com/t/runtime-dependency-between-modules-cause-by-function-definition/47156>\
**Category:** Questions\
**Tags:** module-dependency\
**Created:** [April 11, 2022, 3:23pm UTC](https://forum.elixirforum.com/t/runtime-dependency-between-modules-cause-by-function-definition/47156 "2022-04-11T15:23:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![michel.boaventura](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/m/ecc23a/32.png) [@michel.boaventura](https://forum.elixirforum.com/u/michel.boaventura)\
**Post date:** [April 11, 2022, 3:23pm UTC](https://forum.elixirforum.com/t/runtime-dependency-between-modules-cause-by-function-definition/47156/1 "2022-04-11T15:23:54Z")

</div>

I’m trying to understand why Elixir creates a runtime dependency when we use a module on a function clause.

For instance:

```elixir
# lib/a.ex
defmodule A do
end

# lib/b.ex
defmodule B do
  def foo(A) do
    IO.inspect("A")
  end
end

```

Here module `B` has a dependency on `A` even though we aren’t using anything related to the module itself, it just so happens that `A` is an atom and also a module. If it was just an atom everything would work the same way and we (obviously) wouldn’t have a dependency.

---

<div class="post-metadata">

**Author:** ![stefanchrobot](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/stefanchrobot/32/7657_2.png) [@stefanchrobot](https://forum.elixirforum.com/u/stefanchrobot)\
**Post date:** [April 13, 2022, 6:22am UTC](https://forum.elixirforum.com/t/runtime-dependency-between-modules-cause-by-function-definition/47156/2 "2022-04-13T06:22:13Z")

</div>

I don’t know the answer, but if this is an issue for you, maybe you can use the [Phoenix.Router’s approach to this](https://hexdocs.pm/phoenix/Phoenix.Router.html#module-scopes-and-resources):

> It is very common in Phoenix applications to namespace all of your routes under the application scope:
> 
> ```elixir
> scope "/", MyAppWeb do
> get "/pages/:id", PageController, :show
> end
> 
> ```
> 
> The route above will dispatch to `MyAppWeb.PageController`. This syntax is not only convenient for developers, since we don’t have to repeat the `MyAppWeb.` prefix on all routes, but it also allows Phoenix to put less pressure on the Elixir compiler. If instead we had written:
> 
> ```elixir
> get "/pages/:id", MyAppWeb.PageController, :show
> 
> ```
> 
> The Elixir compiler would infer that the router depends directly on `MyAppWeb.PageController`, which is not true. By using scopes, Phoenix can properly hint to the Elixir compiler the controller is not an actual dependency of the router. This provides more efficient compilation times.

---

<div class="post-metadata">

**Author:** ![michel.boaventura](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/m/ecc23a/32.png) [@michel.boaventura](https://forum.elixirforum.com/u/michel.boaventura)\
**Post date:** [April 14, 2022, 5:27pm UTC](https://forum.elixirforum.com/t/runtime-dependency-between-modules-cause-by-function-definition/47156/3 "2022-04-14T17:27:58Z")

</div>

I’m using Plug alone so I don’t have the `scope` macro, but I ended up cooking something similar to solve the issue, but couldn’t find out why this kind of dependency is needed. Thanks for the reply!
