October 2004 - Posts - Colin's Blog

October 2004 - Posts

Parameter validation

I was thinking the other day that although checking the inputs to functions is something I should probably be doing in my programs, I don't do it very often. There is the argument that it is unnecessary overhead, but I think it probably should be done anyway. Mostly the problem is the hassle of checking the value for 1, 2 maybe more valid ranges etc then throwing exceptions. So I'm thinking that if I can take some of the hassle out of the checks, or at least make them simpler to implement, I would be more likely to do it.

An ideal implementation would be a declarative one, where you have some metadata that indicates the validations, and then some automagic process does the checks, but it doesn't seem very practical or efficient. Probably a better implementation woud be a library of simple checks that can be invoked in one line, and they take care of throwing the appropriate exceptions.

Does anything like this already exist? It doesn't seem like rocket science to implement, but it would definitely be something I will use.

Posted by colin | 8 comment(s)
Filed under: