Why there are no 'physical' object variables (only references)?

Steve Horne stephenwantshornenospam100 at aol.com
Sun Sep 10 15:23:38 PDT 2006


On Sun, 10 Sep 2006 22:03:43 +0300, Kristian <kjkilpi at gmail.com>
wrote:

>Maybe there should be two properties, .dup and .deepdup (or something,
>a name .ddup is probably too similar).

How often is there more than one useful meaning for 'duplicate' for a
particular class anyway? Shallow vs. deep vs. something in between is
usually an implementation detail.

>Really? I mean, a common source of bugs? But isn't it be simple to fix  
>such bugs, just correct the copy methods?

I suspect this is about accidental copying. Parameter passing,
implicit conversions, unexpected temporaries etc.

I have an ideological disagreement against making references
compulsory in a languages that has mutability (any imperitive
language). You can easily get things being changed that weren't
intended to be changed. You save info. for later, but the saved info.
mutates because it wasn't a copy, for instance. In practice, it
sometimes causes me hassles in Python, and probably would in Java if I
used it much.

But pragmatism beats ideology every time. In C# and D the implicit
references work well, for me. There seems to be an intuitive divide
between 'object' and 'value'. For a 'value', I expect parameter
passing to have copy semantics. For an 'object' I expect sharing
(reference) semantics.

Maybe it's something to do with the real world. It's just natural to
work with existing objects - not duplicates of those objects. When I
was told to clean my room as a child, I don't think stories about
duplicating the room, cleaning the duplicate and discarding it would
have worked ;-)

With 'values' - numbers etc - copy semantics seem more sane. In
algebra, calculating the unknowns does not alter the known values.
Outputs are based on inputs, not the other way around. Even feedback
has a time delay - the calculation of the output doesn't change its
input, it just provides a new input for the next millisecond or
whatever.

The trouble is, this is all subjective. The Python one-size-fits-all
everythings-an-object-with-a-reference approach will probably always
bug me, but a lot depends on what you're used to.

-- 
Remove 'wants' and 'nospam' from e-mail.



More information about the Digitalmars-d mailing list