[saga-rg] deep copy / shallow copy

Andrei Hutanu ahutanu at cct.lsu.edu
Sun Sep 11 13:01:25 CDT 2005


Craig Lee wrote:
> At 05:15 AM 9/11/2005, Thilo Kielmann wrote:
> 
>> On Sun, Sep 11, 2005 at 02:10:28PM +0200, Andre Merzky wrote:
>>
>> > The code snippet above is not badly written, but does depend
>> > on the semantics of the copy operator.  Any assignement
>> > operation (so any '=' with SAGA objects involved) will
>> > expose the problem.  But you cannot argue that a programmer
>> > using '=' is writing bad code ;-)
>>
>> Using '=' isn't bad. But creating an alias is
>> (which, in fact, you do here ;-)
> 
> 
> But that's the issue here:  depending on the copy/assignment semantics,
> you are either (1) creating a copy, or (2) creating an alias.
> 
> This means that a SAGA programmer (to avoid "bad" programming)
> would constantly have to be aware of the language binding context,
> since each binding context could have different copy semantics.
> 
> But, one could argue that when programming in a given language,
> the copy/assignment operator will be used for both SAGA and non-SAGA 
> objects.
> That is to say, the programmer should be/will be aware of the
> copy/assignment semantics throughout the program.
> 
> I agree that differing copy/assignment semantics could cause problems
> for a programmer, but I don't see how a SAGA binding could dictate 
> copy/assignment
> semantics that are different from a language's "native" semantics.
> Besides being difficult or impossible to implement, this means that
> different objects within a single program could have different 
> copy/assignment
> behavior, depending on whether they were SAGA or non-SAGA objects.
> This, too, could cause problems.
> 
> I think this should be left as a language binding issue.  Nonetheless,
> the SAGA API doc could have a prominent "Advice to Practitioners"
> section that identifies and discusses these binding pitfalls.
> 

C++ allows both semantics (Java doesn't?) so you still need to make a 
choice,
otherwise different C++ implementations will have different semantics.
I personally like the Java style and also use it in C++
but not having a garbage collector makes it a bit tricky,
you cannot have circular references. Or maybe somebody knows
a good garbage collector for C++ that should be integrated
in the SAGA engine(s) so we don't even have that issue.

Andrei





More information about the saga-rg mailing list