Proposal: Private modules (general discussion)

I think privateing modules will be a cure worse than the disease.

  1. It breaks the semantics of the language. defp (an alias for defprivate) doesn’t allow access to functions outside the module, but defmodulep allows explicit visibility to some modules. Another naming is required.
  2. I think that we should use an annotation, such as: @visible_to: [Foobar] or @scoped_to: [Bar] instead (maybe other names), to tag that this module is not for public usage. This should solve (1).
  3. Although already a rejected idea, what we want to do is to guarantee that private modules are not accessible outside the application/package/library/younameit they are included, which is exactly what we are trying to do here.

Given my ideas, commenting on the proposals:

A. I like this idea, but with another name: @visible_to [MyApp, Foo, ...]. And if any module not in that list tries to use, import or whatever it will be a compilation error, much like what happens when you try to call a defp function outside the module you are defining it.

B, C & D. No because of breaking semantics: explained in (1).

6 Likes