When should I use process-wide dictionary and when should my process state be in the parameters of the loop function?
This:
loop() ->
receive
{From, subscribe} ->
put(listeners, [From|get(listeners)]),
?MODULE:loop()
end.
Or this:
loop(Listeners) ->
receive
{From, subscribe} ->
?MODULE:loop([From|Listeners])
end.
?
Parameters to the loop function has the benefit of being explicit in that nothing outside it can change the parameters (unless you're doing strange magic bouncing on another function like a trampoline), but state tends to add up, and the parameters with them.
How about a dict as a parameter? Best of both worlds or worst of both worlds?