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.


In reply to Re^2: Your use of assertions in Perl ? by SuicideJunkie
in thread Your use of assertions in Perl ? by ady

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.