[erlang-questions] Reassigning variables

Christian chsu79@REDACTED
Wed Mar 18 13:02:17 CET 2009


I dont find these helpful-suggestion-threads for erlang improvement
for erlang to become a more popular language to be all that
interesting anymore (erlang seems to be doing very well on actual
technical merits already). And spokespeople for OTP have already made
it clear that rebinding is not a feature that will ever be added to
Erlang. There is Reia and such approaches for those so inclined.

(Not that Hans is suggesting that feature)

But I think Hans is very close to the real approach: To stop using
silly numbered variables, as they are the real issue.

What is a X1 or a X2 ?

Rather than

X1 = binary_to_list(Bin),
X2 = lists:reverse(X1)

do

String = binary_to_list(Bin),
RevString = lists:reverse(String),

or use

lists:reverse(binary_to_list(Bin))

And when the number of variables grow large, decompose into functions.

PS.

And NO. Rebinding variables is not a good idea. It makes you have to
think about what the value is of a variable now, instead of the much
simpler "what was this variable bound to". The later makes it easier
to understand real code. It is similar to how even the best humans at
multitasking can only do tops 7 things at once. The problem is that
when programming the brain just covers up that it is failing to
understand something, just like none of us are actively aware of the
huge blind spot near the middle of our vision field.
http://en.wikipedia.org/wiki/Blind_spot_(vision).



More information about the erlang-questions mailing list