Reverse Complement utility, Bio::Alg, return value problem

Steven E. Brenner
Thu, 7 Aug 1997 15:52:50 -0700 (PDT)

> > Question: do you propose that set_revcom() also return the object ($self),
> > or should the set_* functions return the modified (or previous,
> > unmodified)  data?  I can see arguments for all three options.
> Ah, we now open a new can of worms! 
> A key motivation for deciding what to return concerns error handling. If  
> the set fails, it's a good idea to halt further processing of the object. 
> With this in mind, it might be safest for the set method to return true 
> or false, depending on the success of the operation. This way, the 
> following code will always work: 
> if($myseq->set_revcom($beg,$end)) {
>    analyze_seq($myseq->get_seq());
> } else {
>    warn "Can't set reverse complement.\n";
> }

I like this, but see below.

[text deleted]

> This degree of error checking is more important as the operations get 
> more complex, such as when an object is responsible for creating a new  
> type of object ($gene->set_protein() or $protein->set_blast()). In my 
> objects, when a complex "set" fails, I actually generate and attach an 
> internal exception to the object which contains data about the error. The 
> process of generating this exception causes the set operation to return 
> false. 
> So I would favor having "set" functions (any function which can 
> modify the object's data) return a status indicator and (possibly) being 
> able to generate an exception that can invalidate the object. The issue 
> of how to deal with exceptions is a separate issue. I don't think I have 
> the best solution yet.

What do you think about simply raising an exception (i.e., croak) if an
invalid operation is attempted.  If the code "cares" about errors, then it
can test for exceptions using eval. 

The advantage of this is that (1) people definitely find out when
something has gone wrong (whereas they may ignore method return values)
and (2) we could potentially return something more interesting from the
set_foo() methods

The disadvantage is that exception handling in Perl is a bit yucky and
thus requires more code.  Without that code, the programs might die with
undesirable frequency.