[erlang-questions] Reassigning variables

Justin Sheehy justin@REDACTED
Tue Mar 17 21:38:15 CET 2009

On Tue, Mar 17, 2009 at 1:02 PM, Matthew Dempsky <matthew@REDACTED> wrote:

>  X = foo(),
>  X1 = bar(X),
>  X2 = xyzzy(X1),
>  blah(X2).

> and later want to change it to:
>  X = foo(),
>  X1 = whee(X),
>  X2 = bar(X1),
>  X3 = xyzzy(X2),
>  blah(X3).

So, what you really wanted was to change:




What's the trouble, exactly?

> This means having to change four lines of code, when really it's
> conceptually just one change.

Every time I've run into something like this, I've found that the real
solution was to make the program use less intermediate variables.

Single assignment is one of the biggest ways in which Erlang helps
reduce bugs.  Please don't try to introduce ways around it, as they
will make programs worse.


p.s. -- (just saw reply from mats) -- Agreed: even when you seem to
need intermediate variables, you often can do even better with
intermediating functions instead.

More information about the erlang-questions mailing list