develooper Front page | perl.perl6.language | Postings from March 2005

Re: return of copies vs references

Thread Previous | Thread Next
From:
Darren Duncan
Date:
March 16, 2005 23:10
Subject:
Re: return of copies vs references
Message ID:
p06210201be5edc3b0234@[192.168.1.102]
At 11:26 PM -0700 3/16/05, Luke Palmer wrote:
>  > For each of the above cases, is a copy of or a reference to the
>>  attribute returned?  For each, will the calling code be able to
>>  modify $obj's attributes by modifying the return values, or not?
>
>Well if you're making accessors, why the heck are you making them
>private?  But I can't really answer your question, because it depends on
>how you write the accessors.

I am writing accessors to mediate with the attributes, which are all 
private, and whose implementation may change over time.  What I want, 
in the normal case, is that calling code which invokes my methods 
will get a copy of attributes which it can modify, that won't affect 
the original attribute values.

When I last asked a related question here, I was told that simply 
returning an attribute will allow the caller to modify the original 
attribute by default.  I wanted to make sure this didn't happen.  It 
is possible that there was a misunderstanding regarding the previous 
question, and the default action is in fact a copy.

-- Darren Duncan

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About