December 02, 2005 | Category:

Code Annoyance

To children and novice programmers:

When writing various kinds of applications or APIs, it is often the case that you will have functions of the form is<em>Object</em>Valid() (or a similar kind of check that begins with “is”), where Object is some variable or object. This is fine: checking data and providing methods to do so is a Good Thing, in that it is considerate and generally fulfills a use case.

Something you should never do is write a function like isObject<em>In</em>valid(). Putting negation into this kind of check is a lot like a double-negative in English, it makes life more difficult for everyone else because they have to spend more time straightening out the negations. This mistake is compounded by the fact it is almost always used in conjunction with the language negation to give: !isObjectInvalid(). Argh!

Next person to do this gets hurt.