[erlang-questions] Parameterized module idioms

Fred Hebert mononcqc@REDACTED
Sat Apr 17 03:55:06 CEST 2010


The biggest 'advantage' of parametrized modules that I see is that you shift
the burden of carrying state from a variable to a module name.

In this module:
-module(y, [Name,Age]).
-compile(export_all).

action1() -> io:format("Hello, ~p!~n",[Name]).

get_age() -> Age.

However, my biggest problem with them show up were I to add the following
function:
ret_fn() -> fun(Age) -> Age + 5 end.

and then tried to compile it, all of a sudden I get the error "./y.erl:8:
Warning: variable 'Age' shadowed in 'fun'". Of course, this is not
problematic if you can hold all the info about the module parameters and
their names in your head, but if you were to look only at the function where
the error takes place, you would get no sign whatsoever of where the error
comes from.
Now if I were to use the variable 'Name' for any other purpose; I'd get a
run time error telling  "** error: no match of right hand side value < ...
>." Again, there I'm having no obvious sign of where the error might come
from -- I have to look for the module definition to know the cause of it.

The way I see it is that parametrized modules reduce the amount of typing
you need to do at the expense of logical simplicity. I'm not sure I'm too
enthusiastic at the idea of making programs harder to reason about for the
sake of typing less.

I guess the problem is going to be less and less apparent with programmers
getting used to it, but yeah. That's my point of view.


More information about the erlang-questions mailing list