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

Ola Bäckström Ola.Backstrom@REDACTED
Thu Feb 25 13:47:20 CET 2016


>From this long discussion I'd like to highlight that namespace handling is larger than just filenames, and that just "fixing" the filename collisions is not good enough. I've digged up two relevant quotes:

2016-02-24 16:07 Fred Hebert wrote:
> [...snip...]
> 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. [...snip...]

2016-02-25 10:17 Vlad Dumitrescu wrote:
> [...snip...] but like it was pointed out before, we have more than module names that are global and that should be compartmentalized: process registry is the most important one. 
> Imagine if the third lib starts and registers a process - there should be two of them, and each lib instance should only know about its own process. [...snip...]

In Erlang all atoms are put in a global namespace so every reference to, for instance, the atom 'ok' is referring to the same atom in an Erlang node (or even cluster of Erlang nodes). This is indeed what we'd like for that atom. Now in some cases we'd like to register a process or an ETS-table and in fact we'd prefer that it is only referenced by our own source code, aka "global but secret". Here's where name clashes can occur, if foreign modules use the same atom.

Common Lisp resolved this a long time ago, albeit in a - at least for me - complex way. But perhaps the underlying ideas could be used:
	* namespaced symbols and 
	* global keywords 
If I remember correctly the keywords are equivalent to Erlang atoms. The existence of two different sorts of atoms are of fundamental importance to the lisp package system and enables lispers to code in different name spaces.

Regards
/Ola




More information about the erlang-questions mailing list