From: Glenn Parker Date: 2005-06-01T23:29:41+09:00 Subject: Re: array of object insert polices dave wrote: > > I wanted to understand what i must check and how to have > a stable code. > > are these rules right in general? > > The imput comes directly from an external source: > - Test with test units. > - Check type and attinence to specifics of data. Type checking is just plain ugly. It's hard to get it right, and it tends to constrain the usefulness of your code. If you need to do it, offer it as a separate, optional method that a caller can run on their input to your code before the real method is used. Only the caller really knows the best time and place to test input, and you will avoid a lot of redundancy and overhead. I would also consider unit tests that verify proper error-handling when an incompatible object is encountered, either via an exception or an error code, or whatever you deem appropriate. Another option is to automatically invoke a coercion method like "to_i" on all input. > The imput doesn't come from directly from an external source: > - Test with test units. > - Don't care about type (duck typing). -- Glenn Parker | glenn.parker-AT-comcast.net |