[erlang-questions] Reassigning variables

Richard O'Keefe ok@REDACTED
Mon Mar 23 03:52:18 CET 2009


On 18 Mar 2009, at 7:07 pm, Matthew Dempsky wrote:
>  - global:resolved/5

This one is a little difficult to follow.
Here's an excerpt:

     S3 = lists:foldl(fun(Node1, S1) ->
	     cancel_resolved_locker(Node1, fun (Tag) ->
	         cancel_locker(Node, S1, Tag)
	     end),
	 end, S, HisKnown),

This computes S3 from S.
It appears that it's only updating _part_ of the state, a list
of 'resolvers'.

As someone reading the code, I have to say that the numbered
variables are very much the least of my worries.  Indeed, to
me they are a _help_, and if the numbering were consistent
(which it isn't: S0 -> S -> S3) it would be more of a help.
>

> but instead to show that it's not just a bad practice limited to my
> code. :P

It's not limited to Dempsky's code.  In *some* cases it is
a bad practice and in others it is not.  In no case is it
a major or even to me a noticeable problem for readability.

The examples I've checked so far fall into three groups:
(A) cases where the numbered variables can be trivially
     eliminated;
(B) cases where Haskell might use a Writer or State monad,
     and some support (-reader(T, ...) and -writer(T, ...)
     declarations) *might* help;
(C) cases where some other data structure (such as a separate
     process or a 'smart' intermediate language) might completely
     eliminate the perceived need for state threading.

However, the main impression I've got from this survey is
that code that relies heavily on state threading in Erlang
tends to be difficult to follow for reasons *other than*
the numbered state variables.




More information about the erlang-questions mailing list