[erlang-questions] The -module line

Loïc Hoguin essen@REDACTED
Fri Nov 21 12:21:40 CET 2014


Hi,

Something has been bugging me for a very long time now.

The -module line is mandatory. It also must be the same as the file name 
minus the extension .erl or compilation fails.

http://erlang.org/doc/reference_manual/modules.html

 > -module(Module).
 > Module declaration, defining the name of the module. The name Module,
 > an atom, should be the same as the file name minus the extension erl.
 > Otherwise code loading will not work as intended.

 > This attribute should be specified first and is the only attribute
 > which is mandatory.

Instead of forcing the programmer to write down the file name, minus the 
.erl extension, and then have the compiler check that the programmer did 
a good job and can have a cookie, can't we have the compiler simply get 
the module name from the file name? The compiler is looking there 
*regardless* so maybe it can save us some time and fetch it itself?

The attribute is mandatory, yes. But it can be just another attribute 
the compiler fills in automatically.

Or perhaps I'm missing an obvious reason as to why we have to fill in a 
line identical to the file name we are feeding the compiler?

I would like to recommend a change that will make the compiler fetch and 
use the file name automatically if the attribute is missing, and error 
out if it's different than the one in the file.

-- 
Loïc Hoguin
http://ninenines.eu



More information about the erlang-questions mailing list