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

Sun Feb 21 10:39:27 CET 2016

> What about:
> Optional -module attribute
> +
> ASCII-only lowercase filenames, composed of only chars non-escapable in a
> terminal (\\, spaces, controls, …)

There are two ideas here.
(1) Restrict module names to a 'portable' subset.
    There are NO non-escapable characters in a POSIX terminal.
    What's more, there are NO characters that might not NEED
    escaping in a POSIX terminal:
        % stty intr s
        % # now try to cancel that
        % s
        % # oh dear interrupt char
        % \s
        % # oh dear no change here
        % ^Vstty intr '^C'
    But anyway, say it's [a-z0-9_] only.
    Still isn't enough: what if the name is too long and the file
    system truncates it?  The POSIX limit is 14, and there have
    been UNIX systems with that limit, so 'abcdefghij.beam' might
    be too long to work as a file name, so limit module names to
    9 characters?

    This approach to safety is not going to work very well.

(2) Make module names optional.

    But in the name of suffering humanity, *WHY*?

    As a human being, when I am looking at a module, *I* want to
    know what the module is called.  I don't give a fewmet what
    the *file* is called, I want to know what the *module* is
    called, which means I want it in the source text where *I*
    can see it.

    Is there any difficulty whatsoever in putting the -module
    directive there?  Nope.  In my editor, ESC[% inserts

    %   File   : <last part of file name is filled in>
    %   Author : <author's name is filled in>
    %   Updated: 20%E%
    %   Purpose:

    -module(<module name is filled in>).


    The module name comes *free* as in *zero* effort.

In short, tying module names to file names IS a problem,
while having -module directives is NOT a problem.

More information about the erlang-questions mailing list