From: Robert Klemme Date: 2005-06-02T00:30:23+09:00 Subject: Re: array of object insert polices Glenn Parker wrote: > 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. There's probably a misunderstanding: you seem to talk about internal type checking for which I completely agree to you. But dave was talking about external data here IMHO. And it's generally considered good practice to check data entered by users or coming into an application via other external sources to make the application robust. Kind regards robert