linter/checker for single-threaded state via numbered variables?

Robert Raschke rtrlists@REDACTED
Mon Jan 27 23:04:38 CET 2020


On Mon, 27 Jan 2020 13:22 Mikael Pettersson, <mikpelinux@REDACTED> wrote:

> Since Erlang doesn't allow you to rebind a variable in a scope where it's
> already bound (that becomes a match instead), there is a convention of
> using numbered variables to denote successive "generations" of some object
> or state that's intended to be used in a single-threaded or linear way.
> For example:
>
> foo(X0) ->
>   X1 = update(X0),
>   case predicate(X1) of
>     true ->
>       X2 = another_update(X1),
>       persist(X2);
>     false ->
>      persist(X1)
>   end.
>
> Here, whenever X(N+1) becomes bound, X(N) should become unused, and it
> should be an error if X(N) did not become unused.  A variation is that the
> "final" value is the one without a number suffix.
>
> Is there any Erlang linter or style checker that can perform these types
> of checks?
>

For what it's worth, I consider this practice a bad code smell. Using
numbered names like that is lazy. Usually such code can be radically
improved upon by using names that properly describe the values they
represent. Very often doing this will start you on the path to simpler code
that ends up not requiring this kind of incremental buildup of "stuff".

Cheers,
Robby
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20200127/2a020aed/attachment.htm>


More information about the erlang-questions mailing list