Proposal: Private modules (general discussion)

Warning could be bypassed in B, C, and D proposals as well, in a little bit more explicit way, but possible as well (and this cannot be prevented as this would break behaviours, i.e. you could not have private GenServer)

defmodulep Private.Foo, visible_to: [Private] do
  def hello, do: "Hello World"
end

defmodule Private do
  require Private.Foo, as: Foo

  def call, do: Bar.call(Foo)
end

defmodule Bar do
  def call(mod), do: mod.hello()
end

As I am generally in favour of the proposal, I would vote for warnings, potentially proposing EEP as well for providing such feature to rest of the platform (then, possibly, with hard error).


After second thought, the C solution is okaish as well I think, provides enough “obscurity” to discourage direct usage, but at the same time it allows to use direct calls.

3 Likes