[Bioperl-l] get/set returns and arrays

Chad Matsalla chad@sausage.usask.ca
Tue, 27 Nov 2001 14:05:11 -0600 (CST)


I have an opinion on something-

I think that get/set methods like this:

sub units {
        my ($self,$units) = @_;
        if (!$units) {
                return $self->{units};
        }
        $self->{units} = $units;
}

should be reversed so that they _always_ return a value, ie like this:

sub units {
        my ($self,$units) = @_;
        if ($units) {
		$self->{units} = $units;
        }
	return $self->{units};
}

Somebody using that object can feel free to discard the result if they are
confident that the set is actually being done but if you want to make
sure, you can always check the result, like this:
ok($object->set_something($number) == $number);

Would anybody object if I do this (always return a value) in my stuff?

And can somebody explain to me why it seems the convention is to return
arrays rather then references to arrays? I am just not sure.

Chad Matsalla