Wednesday, April 06, 2005

Which is the best?

Let's say you have to write a method that returns a value after processing its arguments, and in addition to the return-value it must also return the status code to indicate success or failure in processing the arguments.

Out of the following methods, Foo, which design would you choose?

A method that returns both its return-code and value in a list.
my ($rc, $value) = Foo(@args);

Or, a method that simply returns an undefined value to indicate an error.
my $value = Foo(@args);
die("Damn!") unless ($value);

Or, a method that takes a reference to a variable where the return value must be stored, and returns the status code to indicate an error.

Foo(\$value, @args) or die("Damn!");

Or, a design where Foo returns you the status, and you have to call a separate method to get the result of processing.

Foo(@args) or die("Damn!");
my $value = GetValueFromLastCallToFoo();

Which do you think is the best?

No comments: