linter/checker for single-threaded state via numbered variables?
Tue Jan 28 02:14:55 CET 2020
That's definitely an option, however name generation may be difficult in some cases.
The one I always have problems with is filling cowboy response by calling a cascade of functions updating request structure progressively. I'm not sure if other developers prefer typing ReqWithHeaders, ReqWithContentType, ReqWithBody, ReqHalted to consecutive but otherwise meaningless numbers.
On 28 January 2020 9:04:38 am AEDT, Robert Raschke <rtrlists@REDACTED> wrote:
>On Mon, 27 Jan 2020 13:22 Mikael Pettersson, <mikpelinux@REDACTED>
>> Since Erlang doesn't allow you to rebind a variable in a scope where
>> already bound (that becomes a match instead), there is a convention
>> using numbered variables to denote successive "generations" of some
>> or state that's intended to be used in a single-threaded or linear
>> For example:
>> foo(X0) ->
>> X1 = update(X0),
>> case predicate(X1) of
>> true ->
>> X2 = another_update(X1),
>> false ->
>> Here, whenever X(N+1) becomes bound, X(N) should become unused, and
>> should be an error if X(N) did not become unused. A variation is
>> "final" value is the one without a number suffix.
>> Is there any Erlang linter or style checker that can perform these
>> 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
>that ends up not requiring this kind of incremental buildup of "stuff".
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions