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

Cons T Åhs cons@REDACTED
Wed Feb 17 14:58:56 CET 2016


On 17 Feb 2016, at 10:45, Konstantin Vsochanov <kost@REDACTED> wrote:

> Hi!
> 
> I’m working with Erlang for two years now and enjoy every day of using
> it. However, there are some strange  features I’m wondering about. One
> of them -module() attribute.
> 
> The module name is strictly defined by the name of the .erl file. You
> can’t change module name with -module() attribute.


Actually, you can.  If you give the option no_error_module_mismatch to compile:file/2 as in

42> compile:file(baz, [no_error_module_mismatch]).

the file baz.erl can contain a -module() directive with another name than baz.  Note, however, that you need to use code:load_binary/3 to load the resulting beam file.

Cons

>  But the the -module()
> attribute is mandatory. Why? Why we need -module() attribute at all?
> Maybe we can make -module() optional in next Erlang release? So we don’t
> need to repeat file name in first string of every .erl file. Or maybe I
> miss something important?
> 
> Feedback is appreciated!
> 
> - Konstantin Voschanov
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list