[erlang-questions] Parameterized module idioms

Mazen Harake <>
Tue Apr 20 17:15:30 CEST 2010


This boggles me:

If you create a new "instance" of a module with a parameter, then you 
need to have that "instance variable" around to call it right? So you 
need to keep it somewhere... as a state.

So in any case you need to keep a state, in other words you haven't 
achieved anything (except perhaps making your code more obfuscated).

So _why_ is it ["of course"] "easier to use module parameters instead of 
passing closures or state around"?

I must be missing some important detail somewhere...

/Mazen

On 20/04/2010 16:04, Vlad Dumitrescu wrote:
> Hi,
>
> There have been many interesting arguments for and against
> parametrized modules and I will add a couple of my own, that reflect
> my feelings about them. I am lazy and will not quote the original
> text, I hope that won't create misunderstandings.
>
> * Of course it's easier to use module parameters instead of passing
> closures or state around. Just like it's easier to use global
> variables instead of function arguments. That is, as long as you can
> remember them all and until something breaks because of a change in a
> seemingly unrelated module... There's a reason some people like the
> functional style better.
>
> * Personally, I don't think it's a good idea to try to graft features
> on a language, for which it wasn't designed from the start. Most of
> the time the result is an ugly hybrid. It feels a lot better to
> implement different languages targeting the platform, each matching a
> different style.
>
> * Parametrized modules aren't the same thing as modules as a data
> type. At the moment, they are basically syntax sugar and there are
> some weird effects (bugs!) because of that:
>        >  {lists,hello,world}:reverse([1,2,3]).
>        [3,2,1|{lists,hello,world}]
> The (higher-level) reason for this bug is just that there is no module
> data type to query if it is parametrized or not.
>
> best regards,
> Vlad
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:
>
>    

---------------------------------------------------

---------------------------------------------------

WE'VE CHANGED NAMES!

Since January 1st 2010 Erlang Training and Consulting Ltd. has become ERLANG SOLUTIONS LTD.

www.erlang-solutions.com



More information about the erlang-questions mailing list