[erlang-questions] Parameterized module idioms

Vlad Dumitrescu vladdu55@REDACTED
Tue Apr 20 21:04:43 CEST 2010


On Tue, Apr 20, 2010 at 17:15, Mazen Harake
<mazen.harake@REDACTED> wrote:
> 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"?

Hi,

If you send state around the functional way, it has to be a parameter
to all the functions that use some part of that state. If the state
data changes, it may be needed to update all these places (if the
state representation wasn't flexible enough).

If the state is globally accessible, you just use the appropriate
variable where it is needed.

regards,
Vlad


More information about the erlang-questions mailing list