Only an Idiot Would Misrepresent Opinions on Validation


I recently came across Raymond Chen's nearly-two-year-old article "Only an idiot would have parameter validation, and only an idiot would not have it". It was interesting, and so were the comments, but I think Chen's account of the situation is flat-out wrong.

After mentioning that people's reaction to Win3.1's new feature of parameter validation was "It's about damn time", he says:

"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. "

Unless there's some real doofuses that I haven't come across, parameter validation is not out of fashion (and wasn't two years ago, either). What's out of fashion is responding to those failure conditions with a mere return code instead of something like an exception.

Getting rid of parameter validation does not amount to "crash and burn with a big red fat'n'ugly blinking exception". It can, but not reliably so - only if you happen to be lucky. And maybe it's just that I don't get out enough, but I'm not aware of anyone who does consider ignoring error conditions to be a reliable way of making an app shout "Failure, failure!" from the rooftops. Maybe it really was back in Win3 as Chen suggests, I don't know, but it's not the case now.

Although, what possibly has flip-flopped (and perhaps this is where Chen got mixed up) is the idea that returning a "bad params" return code is better than forging on and letting shit hit the fan (FWIW, I'm not sure which way I lean on that). I don't think that change in popular opinion happened for entirely unreasonable...umm, reasons. It sounded good at the time, and then we learned it doesn't work out as well as we had hoped in actual practice. So some people are on the other side of the fence now. Live and learn.

BTW, In the title of this, I'm not calling Raymond Chen an idiot. I'm making a play on words with his article's title. So there. Idiot.

Leave a comment

Captcha