December 10th, 2009

Only an idiot would have parameter validation, and only an idiot would not have it

The great thing about parameter validation is that there are people who say that only idiots would have it, and other people who say that only idiots wouldn’t. Back in the old days, Windows didn’t do parameter validation. If you called a function with an invalid window handle, your application crashed. If you called a function with an invalid pointer, your application crashed. If you called a function with an invalid bitmap handle, your application crashed. There was a lot of crashing going on. These crashes manifested themselves in the infamous Unrecoverable Application Error dialog, commonly known as the UAE message. Windows 3.1 added parameter validation to all of the functions in KERNEL, USER, and GDI. If an application passed an invalid window handle, then instead of crashing, it just got an error back. This change was met with derision. “Oh, I’m so impressed. You finally got around to doing something you should have been doing all along. Not doing parameter validation was a totally idiotic decision.” But nowadays, parameter validation is out of fashion again. If you detect an invalid parameter and return an error code, then all you’re doing is masking a latent bug in the application. It should crash and burn with a big red fat’n’ugly blinking exception. In other words, we should go back to the way things were before we added parameter validation. (Well, except that the bit fat ugly exception wasn’t red and it didn’t blink.)

Who’s the idiot now?

Topics
Other

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.