When should I use the dictionary for the whole process and when should the state of the process be in the parameters of the loop function?
It:
loop() ->
receive
{From, subscribe} ->
put(listeners, [From|get(listeners)]),
?MODULE:loop()
end.
Or that:
loop(Listeners) ->
receive
{From, subscribe} ->
?MODULE:loop([From|Listeners])
end.
?
The parameters of the loop function have the advantage that they cannot change the parameters anything (unless you make a strange magical bounce on another function, for example, a trampoline), but the state tends to add up, and the parameters with them.
How about dict as a parameter? The best of both worlds or the worst of both worlds?
source
share