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

Nathaniel Waisbrot nathaniel@REDACTED
Fri Feb 19 15:03:17 CET 2016


> for myself I am now wondering why we dont have a `-module` block and then ignoring the filename completely.
> 
>     -module(some).
>     -endmodule.


This sounds nice. I think the first thing I’d do is start putting my application and top-level supervisor code in the same file (they’re generally small enough to both fit on one screen together). The second thing would be to wish that I could declare the same module in multiple files and have the compiler combine them for me:

foo.interface.erl:

    -module(foo).

    -export([poke/0]).

    poke() ->
      gen_server:cast(?MODULE, poke).

    -endmodule.


foo.gen_server.erl:

    -module(foo).

    -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).

    handle_cast(poke, State) ->
    %% …

    -endmodule.



After that, I’d start wondering about monkey-patching, so there’s that to watch out for.

-------------- 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/ffaa1b1f/attachment.bin>


More information about the erlang-questions mailing list