[erlang-questions] Why we need a -module() attribute?
Sun Feb 21 10:20:03 CET 2016
> On 02/19/2016 01:00 PM, zxq9 wrote:
>> On 2016å¹´2æ19æ¥ éææ¥ 12:32:11 LoÃ¯c Hoguin wrote:
>> Why is having this attribute a problem?
> You never had the error that the module name doesn't match the file name?
Having the file name wrong is a problem.
Having -module in the file is a SOLUTION to that problem.
Has everyone forgotten the Xerox Lesson?
Back in the 80s it was on everyone's lips at Xerox PARC,
or at any rate everyone's lips who spoke to me.
A PROGRAM IS NOT A LISTING: A PROGRAM IS A DATABASE.
This mantra frees you to imagine things like versioned modules
in a non-versioned file system, or treating modules (or even
parts of modules) as things that can be stored in a data base
under some kind of authentication scheme.
> Considering the current compiler code checks that you are a good little
> kid and wrote the same module name as the file name, I don't think that
> an hypothetical file system was in OTP team's mind when they made the
> -module mandatory.
No, the compiler is not checking that YOU are a good little kid.
The compiler is checking that the FILE SYSTEM hasn't broken things.
To repeat an earlier example, I've copied a file named
'tests.erl' onto a memory stick (system X), read it on
another system (system Y) with no trouble, and failed
miserably on another system (Z) because the file is
actually called 'TESTS.ERL' on the memory stick. This is
the file system mucking things up and it HAPPENS.
> And frankly, if I were to base all my decisions based on hypothetical
> changes 50 years from now I wouldn't write any code. I can't predict the
> future. Can you?
How about predicting the present?
We have to deal with mutually incompatible file systems NOW.
According to http://erlang.org/doc/man/code.html you can
load modules from .ez files NOW, and the name of a pseudo-file
inside a .ez file is *not* required to follow the rules of the
host file system.
More information about the erlang-questions