[erlang-questions] Process scope variable

Fred Hebert mononcqc@REDACTED
Thu Feb 19 15:17:53 CET 2015


On 02/19, Imants Cekusins wrote:
> >  instead of State you have Pid
> 
> a fun can return just what it did, without
> {Return, State}
> 
> so no more
> S1 = a(State),
> S2 = b(S1)
> 
> simply
> a(Pid)
> b(Pid)
> 
> also, given simplified standard signatures, I do not need to navigate
> the full spagetti path to check & recheck if I call a fun correctly.
> 
> refactoring will take me at least 50% less time.

You do realize that what you did is introduce the equivalent of a global
mutable variable into your program, right?

You no longer need to navigate the full spaghetti to check if the
function is called correctly, true (which is easy to do *automatically* when
you have things such as Dialyzer, by the way).

Instead you now have to navigate the full spaghetti whenever something
goes wrong because one of the calls -- any of them -- goes wrong. And
now you need to explicitly trace or weave out the state in the other
process whenever it behaves funny, checking the full spaghetti with a
lot more pain than you would have otherwise.

Will refactoring take 50% less time because you won't need to properly
understand what goes on before you do it, or because you dislike
sequences of variables needing to be renumbered?

If a function call fails and your process ends up killed, are the
mechanism to figure it out well thought out? You realize you implicitly
changed the use of a direct stacktrace into asynchronous error handling
via monitors and links, right? This is doable, but has a cost, too!
You'll be splitting the error source from its handling. This is
desirable in isolated processes doing isolated tasks, but is it
desirable in this case?

Have you, for example, considered calling `b(a(State))' ?

Regards,
Fred.



More information about the erlang-questions mailing list