in reply to Re: Your use of assertions in Perl ?
in thread Your use of assertions in Perl ?
I can't agree more.
There have been so many times where I have been stuck sitting there knowing that what I want to do will work, but not being allowed to do it.
For a concrete example: a monitoring program which sends alerts when your server's disk starts to get full at $work. I want just a "warning" at 100% full, not a "critical", since the disk in question is very low priority and I don't want the system to cry "Wolf!" The obvious solution is to set the critical level to 101% full, and therefore it will never trigger, leaving 100% for the warning.
Naturally somebody went and made the GUI only allow 0-100% to be entered, and also require something in the critical field. Yet, if you snoop around in the database and poke 101 into the correct cell, it all works perfectly as intended. Unfortunately you can't do workarounds like that and still expect corporate support for it.
...Anyways... I would just like to say to all the assertive coders:
Please do not assert that the input is within an expected range.
Instead, assert to protect against things which will make your function fail.
Note that this is the opposite of taint checking; instead of only allowing known-good data from untrusted users, your users are now the authors useing your module. They are fully trusted (and can edit your code if they really want to), so you want to maintain the maximum flexibility while providing some convenient notification when they're about to burn themselves.
The distinction here is the difference between a guard rail on the highway and the padded rubber room your power users will require after trying to use your code. :)
PS: this, of course, only applies to modules that do not interact with untrusted users. If taint checking is a good idea for your module, then highly restrictive assertions are probably a good idea too.
|
|---|