[erlang-questions] Why we need a -module() attribute?

Fred Hebert mononcqc@REDACTED
Wed Feb 24 16:07:07 CET 2016


On 02/24, Konstantin Vsochanov wrote:
>
>Regarding modules, I think the flat space for module names is more
>troubling. If you look at almost any Erlang library/application, you can
>see, that file names are like
>
>myapp_file1.erl
>myapp_file2.erl
>myapp_subsystem1_file1.erl
>...
>
>So we manually implement hierarchic module system. It's a clear sign,
>that something going wrong or is missing.
>

It is, but it has some far-reaching implications that are easy to forget 
about when you don't do namespacing by hand. For example, ETS tables and 
processes can both be named, and if you do not manually namespace them, 
the same clashes can happen as would with modules.

So we have to be aware of that. Designing a module namespace without 
having a way to expand this to process names and tables can yield fairly 
confusing cases where only parts of the system clash, but not others, 
and where things can remain nearly as tricky as they would otherwise be.

I'm pretty sure `user' is the module that trips people up the most for 
that reason. HAving a namespace letting you run the equivalent of the 
current `my_project_user' and calling it as `user' in code could work, 
but if you try to register it as `user' you will fail since `user.erl' 
already does this at system boot (unless the --nouser option is passed 
to the VM).

It is easy to think of simple solutions that ultimately don't cover 
enough cases, I'm not sure how things could reasonably be done with the 
actual ecosystem though.

Regards,
Fred.



More information about the erlang-questions mailing list