Thank you for taking the time to respond.
The most helpful link was the perl-porters link, which
lead me to this discussion of the assertion pragma started by Ricardo SIGNES started in June, 2007, a month before it was removed:
Assertions, warts, and all.
The upshot of the discussion is that
- the pragma was meant to allow the development of flexible assertion routines that could make their own decisions about how to construct an assertion from inputs
and how to handle the failure of that assertion. Do we die? warn? log? etc, etc.
- you can force code to be optimized away using if (SOME_CONSTANT) { ... } but many people feel that creates too much line noise and obscures the general flow of code.
- however, when a pragma attached to a routine defined in module X causes a call in module Y to get optimized away at runtime, confusion results. It is *way* too easy for people to write things like die unless foo_ok(...), completely blind to the fact that foo_ok(...) is an assertion that can disappear at runtime and turn into die unless 0.
So how did this conversation turn into a decision to remove the pragma? It seems to me that the goals were good and there were other ways to address the last issue without removing the pragma. Why were they not taken?
The goal of reducing line noise is essential to code readability. The goal of flexible assertion strategy is essential to encouraging people to actually use assertions.
One way to deal with die unless foo_ok would be to prohibit any sub marked as an assertion from being part of a conditional. This would structurally enforce a core tenet of assertions: they shouldn't have side effects in operational code.
The reason I asked the question is that neither the perl delta nor the CPAN assertions module (both of which you cited) explains the decision. The CPAN module doesn't
even mention it. It was last updated in June, 2005 and the decision to remove the assertions pragma took place two years later in July, 2007. A general search on "assertions" (which I did both via google and perl monks) tends to mostly show up lots of stuff on regular expressions.
beth
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.