> > I would prefer it to return the old value:
> >
> > sub foo {
> >   my $self = shift;
> >   my $old_foo = $self->{'foo'};
> >   $self->{'foo'} = shift if @_ > 0;
> >   return $old_foo;
> > }
> >
> >
> 
> If you set a new value, why would you want your client to still be
> using the old value?

Because you may need to put the old value back.  It's more of a
philosophical question.  "What should the mutator return?" 

The Object Purist says, "Nothing -- it should be declared void."

Another school says, "It should return the value you just set it to".
I think is useless -- it's a tautology.  You KNOW what value you just
set it to.

Yet another thought is "The previous value" -- that is at least
something you didn't know going INTO the call - so it does increase
the total knowledge of your program.

My hitherto prefered answer is "It should return the object."  Only
because I (used to) like to chain method calls.  I've since lost this
bad habit.

        $fruit->name('apple')->color('red')->texture('crunchy');

So, I am now wavering between the 'previous value' and 'nothing'
options.  

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
        Lawrence Statton - [EMAIL PROTECTED] s/aba/c/g
Computer  software  consists of  only  two  components: ones  and
zeros, in roughly equal proportions.   All that is required is to
sort them into the correct order.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to