[BioRuby] (no subject)

Pjotr Prins pjotr2006 at thebird.nl
Tue Jan 31 07:30:57 UTC 2006


Dear all,

In the tutorial we write:

  So when using String methods, you should subtract 1 from positions
  conventionally used in biology.  (subseq method returns nil if you
  specify positions smaller than or equal to 0 for either one of the
  "from" or "to".)

and I added:

  (EDITOR'S NOTE: should 'subseq' not throw an exception instead?)

Can someone state what is the preferred design? I personally think an
exception should be thrown to warn a programmer something is wrong -
i.e. this is an exceptional situation ;-). Returning a nil may lead to
nicer looking loops, but it does not help writing good programs.

Regarding the exception vs return code issue, I think Martin Fowler's
Refactoring says all that need to be said :

- Returning an error code to indicate an error is a code smell because
	you could miss the error checking
	(http://www.refactoring.com/catalog/...hException.html)

- Throwing an exception on a condition the caller could have checked
	first is another code smell because it makes the caller code hard
	to read
	(http://www.refactoring.com/catalog/...onWithTest.html)

Pj.



More information about the BioRuby mailing list