[erlang-questions] process dictionary, anyone?

Sean Hinde sean.hinde@REDACTED
Mon Apr 30 11:35:14 CEST 2007


On 30 Apr 2007, at 10:11, Ulf Wiger ((TN/EAB)) wrote:

>
> I agree that it's easy to abuse the process dictionary,
> but I can't see that using ets is any better. So the
> advice should be to avoid certain programming patterns.
>
> Most importantly, don't sprinkle side-effects all over
> your code, but try keep as much of your code as
> possible side-effect free.
>
>
> Comparing the process dictionary an ets, there are
> pros and cons with each:

Snip lots of good differences.

>
> In short, I'd say that the process dictionary is
> no worse than any other kind of side-effect, but
> has some fairly unique advantages as well.

I'd say you missed one very important difference, which is that the  
process dictionary is "just there" waiting to be (ab)used, whereas an  
ets table must be explicitly created before use. My guess is that  
this difference leads to the typically very different uses people put  
the two mechanisms to.

To use an ets table you must have a convenient place to create it,  
which typically means the init function of a gen_server, which leads  
to typical use - extra state for a process, no worse than updating  
the State record, but with fast access for large data sets.

The process dictionary OTOH can be used much more conveniently in  
what would be otherwise pure library code, relying on the existence  
of the process dictionary in whatever random process calls it. This  
would be the "handy hack for not re-factoring" mode which is almost  
always bad.

Another important difference is that ets tables are limited in  
quantity. Using ets in "handy hack" mode can easily take down the  
node - one new ets table for each time the function is called.

BR,
Sean


>
> BR,
> Ulf W
>
>> -----Original Message-----
>> From: erlang-questions-bounces@REDACTED
>> [mailto:erlang-questions-bounces@REDACTED] On Behalf Of
>> Torbjorn Tornkvist
>> Sent: den 30 april 2007 10:12
>> To: erlang-questions@REDACTED
>> Subject: Re: [erlang-questions] process dictionary, anyone?
>>
>> Tony Rogvall skrev:
>>> Hi !
>>>
>>> I think most of us has used put/get at some point.
>>> It will ALWAYS hit you back. You will spend hours trying to
>> locate the
>>> place where things went wrong. I do use put/get and I think
>> you will
>>> too.
>>> But it's NOT a great little hack it's a disease.
>>
>> Well spoken Tony!
>>
>> To all Erlang newbee's: stay away from the process dicts!
>> In fact, try to stay away from any destructive operation.
>>
>> After 15 years of Erlang hacking I almost never use the
>> proc.dict (perhaps once every third year or so...:-)
>>
>> Cheers, Tobbe
>>
>>>
>>> Happy hacking
>>>
>>> /Tony
>>>
>>>
>>>
>>> On 30 apr 2007, at 00.53, Bob Ippolito wrote:
>>>
>>>> You can represent any non-functional construct with
>> message passing.
>>>> A side-effect is a side-effect... Erlang is clearly a hybrid
>>>> language, but it has a very useful subset that is purely
>> functional.
>>>> Much of what I've read in the standard library is written in that
>>>> purely functional subset, and the syntax and features of the
>>>> language/VM seem like they're designed to encourage and
>> support mostly that subset.
>>>>
>>>> Using the process dictionary is a great little hack that saves you
>>>> from refactoring a bunch of code to include an extra state
>> variable...
>>>>
>>>> -bob
>>>>
>>>
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://www.erlang.org/mailman/listinfo/erlang-questions
>>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list