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

Kristian kjkilpi at gmail.com
Tue Sep 12 06:16:22 PDT 2006


On Mon, 11 Sep 2006 01:23:38 +0300, Steve Horne  
<stephenwantshornenospam100 at aol.com> wrote:
[snip]
>> 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.

Yes, these things could cause harm. I have had a few incidents with  
unxcepted temporaries (only few fortunately).

[snip]
> 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.

Well said. Usually (I think/hope) objects are 'unique' with no need to  
copy them. You just have to adjust your thinking.

However, sometimes 'working objects' are needed in calculations. But, as  
said, structures are for that. I am just wondering that should structures  
indeed have constructors and destructors. It would allow one to create  
more complex data types. Probably interfaces wouldn't hurt either.

And another thing that I have no clear grasp yet is unability to  
copy/clone class objects. For example:

class Obj;

void func(Obj obj) {
     Obj tmp;

     tmp.clone(obj);
     //modify 'tmp'
     ...
     //use 'tmp' instead of 'obj'
     ...
}

Or you just need to store objects for later use.
These things cannot be done currently. How often that would be necessary,  
in practice? (Once is enough to give you gray hair...?)



More information about the Digitalmars-d mailing list