Sanity Checker

Both pattern and AntiPattern, depending. A SanityChecker tests for obviously incorrect values before proceeding. This is a pattern when used as form validation, which tests (for example) the association of a user's zip code and state, or for first and last names that consist of all blanks/single letters/curse words/etc. Sanity tests can give false positives. A user with a New York zip code in California is obviously wrong, but more elaborate testing is needed before the _real_ address is determined.

The AntiPattern Sanity Checker works like this: The developer writes some code which blows the stack, or loops infinitely:

do {

//Coax some values

} while (values ! reach nirvana);

Said developer decides to prevent the infinite loop in this manner:

int counter=0;

do {

  if (counter++>1000)
    throw Exception
//Coax some values.

} while (values ! reach nirvana);


EditText of this page (last edited June 3, 2006) or FindPage with title or text search