[BUG] Dictionary equality test

Richard A. O'Keefe ok at cs.otago.ac.nz
Thu Jun 20 02:59:11 UTC 2002


Chris Muller <afunkyobject at yahoo.com> wrote:
    [A courteous end to this thread.]

Thank you very much.
	
	I also still support my general theme of sharing instances of
	*user-created* classes, which is completely unrelated to this
	discussion.

I don't see the reason for the restriction to *user-created* here.

Sharing is good when
 - the objects that are shared are (effectively) immutable once
   sharing begins.  By "effectively" I mean that various kinds of
   internal caching and rearrangement are fine as long as they
   don't lead to differences of behaviour.  By "once sharing begins"
   I mean that potentially mutable things which will not in fact
   be mutated once they are shared are OK.

 - the purpose of the sharing is to provide a communication path;
   client X pokes shared object Y so that client Z will see the change.

 - the sharing is invisible.  Here I'm referring to the kind of
   "copy-on-write" trick that SETL taught me.  You might have Substring
   objects, for example, pointing to a shared String; when you change
   one of the substrings, it makes a copy of (its part of) the shared
   string and changes that.  This has been used in several libaries
   to provide fast substring operations.

Apart from that, it can be dangerous.

Here's an example, adapted from one of the Ducasse articles:

    Demo>>
        mutatedArray
            |a|
            a := #(1 2 3 4).
            a at: 2 put: 17.
            ^a
...
    x := Demo new.
    y := Demo new.
    a := x mutatedArray.
    b := y mutatedArray.
    b at: 3 put: 48.
    a <<printit>>
==> #(1 17 48 4)

Beginners are often surprised that a and b are the same object.

This cropped up in Eiffel.  People were getting so confused about
whether string literals were shared or copied that new syntax was
added:
    s := "abc" -- new copy, change it all you want
    t := once "abc" -- shared literal, change it at your peril

I am particularly fond of 'persistent' data structures, such as AVL DAGs,
which let you keep multiple versions of a linked structure at the same
time.  But this is sharing that is hidden from the outside; from the
outside you think you have immutable objects, and the interface for
doing an edit has the same observable behaviour as making a complete
new copy, except for time and space requirements.




More information about the Squeak-dev mailing list