Impressions of Mozart-Oz

Ulf Wiger <>
Sun Dec 15 23:11:02 CET 2002


On Sun, 15 Dec 2002, Roger Price wrote:

>On Fri, 13 Dec 2002, Vance Shipley wrote:
>
>> Q:  Where are the global variables?
>> A:  There are none....  Don't use the process dictionary.
>                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
>What's wrong with the process dictionary? Is it a matter of
>performance, or programming style, or something else?

Programming style. It introduces a form of get-put
programming that breaks referential transparency.

Of course, so do message passing and ets as well. The
warning about the process dictionary pre-dates ets, but
holds every bit as much for ets -- more so for public ets
tables, as they essentially allow all processes to share
data, similarly to global variables.

Referential transparency is perhaps the one feature that
functional programming afficionados like to hail as The
Great Advantage of Functional Programming. But since Erlang
has been officially re-labeled a COPL (Concurrency-oriented
Programming Language) by Joe Armstrong, it is a perfectly
reasonable question. (:

Referential transparency means that you can trust that a
function will always return the same value if called with
the same function arguments. A function that relies on the
contents of the process dictionary, the message queue, or
ets/mnesia tables is not referentially transparent.

Another way of putting it would be that you cannot simply
read the code of a function and figure out exactly what it
does.

If you think ets is really neat, you may conclude that the
process dictionary has been unfairly accused. In some
respects, the process dictionary is actually handier than
ets (no copying, its contents are included in crash reports,
etc.) And -- well -- mnesia uses it, and so does proc_lib.

However, all sources of side-effects are potentially
dangerous, and will made the code harder to understand if
not used with discipline.

/Uffe
-- 
Ulf Wiger, Senior Specialist,
   / / /   Architecture & Design of Carrier-Class Software
  / / /    Strategic Product & System Management
 / / /     Ericsson Telecom AB, ATM Multiservice Networks




More information about the erlang-questions mailing list