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

Tony Rogvall <>
Fri Feb 19 23:26:04 CET 2016


> On 19 feb 2016, at 21:52, Joe Armstrong <> wrote:
> 
> While on the subject of modules ...
> 
> I think there should be 'anonymous modules' and registered modules
> (just like processes):
> 

I even had it implemented in the first SMP prototype while trying to find
cheap ways of doing the code loading.
Just think how nice this would blend in with a gen_server, just pass it the
anonymous module code and the code is upgraded.

It worked like a charm. :-)

Cheers

/Tony


> For processes:
> 
>    Pid = spawn(fun() -> ... end)
> 
> Creates a process, but only the process which created the process can say
> 
>    Pid ! Message
> 
> Other process do not know the value of Pid so they can't send any
> messages to Pid.
> 
> This is inconvenient so we can say register(foo, Pid) and thereafter *any*
> process can say `foo ! Message`
> 
> I would like to see:
> 
>    Mod = load_code(Bin)
> 
> after which the parent can say Mod:func(....) and register(Name, Mod)
> and then *any* process can call foo (just like registered processes)
> 
> With such a mechanism we could declare and use private modules which are not
> globally visible.
> 
> (The same should be true for ets tables and ports) - also Modules
> should be linkable
> and sent exit signals to their link set when deleted.
> 
> Just make everything behave like processes.
> 
> Cheers
> 
> /Joe
> 
> 
> On Fri, Feb 19, 2016 at 6:00 PM, Fred Hebert <> wrote:
>> On 02/19, Loïc Hoguin wrote:
>>> 
>>> 
>>> You never had the error that the module name doesn't match the file name?
>>> 
>> 
>> Frankly the only times I got the error was when I was either:
>> 
>> 1. Making copies of modules for benchmarks or comparisons and forgetting to
>> change the names. This error was necessary since I couldn't run 3 modules
>> all with the same name without issue. Much appreciated
>> 
>> 2. Moving files around and I forget to rename the module. I tend to like
>> things to be in order and I appreciate the reminder that renaming a file
>> means I should probably rename the module.
>> 
>> It's annoying that it's mandatory, but I can't really think of too many
>> cases where I want to look for a module, and must find it in a
>> differently-named file. I guess I could use grep/awk/ack to move around, but
>> I quite like just opening a file with the right name.
>> 
>> I always thought of the feature as a net positive given it forces me to keep
>> things clean and consistent.
>> 
>> One module per file is something I'm more open to argue about, but filename
>> must match the module name is definitely a plus for me.
>> 
>> _______________________________________________
>> erlang-questions mailing list
>> 
>> http://erlang.org/mailman/listinfo/erlang-questions
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160219/186a13a7/attachment-0001.bin>


More information about the erlang-questions mailing list