ELISHEVA has asked for the wisdom of the Perl Monks concerning the following question:

Perl 5.9.0 introduced a code attribute assertion. This was removed in Perl 5.9.5 after being deemed "insufficiently mature". Could anyone tell me the story behind this? What exactly was the reason for its removal? And is it ever likely to come back? (it is not in Perl 5.10.0).

Many thanks,

beth

Replies are listed 'Best First'.
Re: the assertion pragma
by Anonymous Monk on Dec 19, 2008 at 05:40 UTC

      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
        An idea, best to ask those who remove it :)