Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Acme::Don't

by rob_au (Abbot)
on May 10, 2002 at 03:16 UTC ( #165585=modulereview: print w/ replies, xml ) Need Help??

Item Description: The opposite of do

Review Synopsis: Something more than just a gimmick and an interesting use for Perl4 module pragma

 

Acme::Don't

 

This module, from the warped mind of Damian Conway, provides only one export, the don't command. This command is used in exactly the same way as the do BLOCK function except that, instead of executing the block it controls, to quote the module POD, "it...well...doesn't".

The result of wrapping a code block by the don't command is a no-operation which, regardless of the contents of the block, returns undef.

Why review this module? Well, in contrast to many of the other modules which have found their way into the Acme:: namespace, I can actually see a use for this module in development. How many time have you been working on some code and wanted to comment out a section of it to test specific code components? With Acme::Don't, it is as simple as adding the surrounding don't block! The only caveat with this debugging and development approach is that code within the don't block must be syntactically valid, providing compile time-syntax checks without execution. Additionally, it should be recognised that this statement is not all encompassing with BEGIN blocks placed within a don't block still being executed - For example:

use Acme::Don't; don't { BEGIN { print "foo"; } print "bar!\n"; }

The above code still produces the output of "foo" as a result of the BEGIN block execution.

Other caveats of this interesting module are included in the module documentation and while this module resides within in the Acme:: namespace it might just be something more than a gimmick and an interesting use for Perl4 module pragma :-)

 

Comment on Acme::Don't
Select or Download Code
(kudra: if (0) {} ) Re: Acme::Don't
by kudra (Vicar) on May 10, 2002 at 10:28 UTC
    I admit to not having used the module in question, but from the description, it sounds as if you'd be just as well served by wrapping the code in if (0) { }, which doesn't require the use of an extra module. Maybe I'm missing something, but from the description here, it looks to me like just an amusing use of Perl4 module naming syntax.
Re: Acme::Don't
by cjf (Parson) on May 10, 2002 at 10:45 UTC

    As Simon Cozens points out in Where Wizards Fear To Tread, Acme::Don't doesn't support double negatives either. The following code doesn't print anything.

    my $x = 1; don't { print "Something\n" } unless $x;

    I don't see it as being at all useful, but I doubt it was intended to be used at all :). However, I can think of a few good uses for Acme::Bleach. If I can just remember where Matt's script archive is... ;-).

Re: Acme::Don't
by seattlejohn (Deacon) on May 10, 2002 at 17:16 UTC
    Hmmm. When I want to comment out a block of code for testing purposes, my usual approach is to enclose it in POD directives:

    # normal code here =pod commented out for testing any code in here won't run; in fact it won't even be syntax-checked =cut # more code
Re: Acme::Don't
by Juerd (Abbot) on May 10, 2002 at 22:29 UTC

    How many time have you been working on some code and wanted to comment out a section of it to test specific code components?

    Often.

    q{ ...; ...; };
    Perl will optimize this away, so there's no execution speed involved. Probably the best thing about this is that many color highlighting editors will mark this as a string (which it is), so you can see that it's something not-normal. BEGIN blocks are not BEGIN blocks anymore, they are just part of the never-executed string. It doesn't do any syntax checking (well, you do have to balance your {}'s, or have to choose other delimiters).

    Update (Aug 15 2002):

    15:07 <@kane_> juerd: it looks elegant, but wanrs =) 15:07 <@Juerd> kane_: I know, but it's perfect for development code. T +he warning is a good reminder, too 15:08 <@Juerd> I can't believe I didn't say anything about warnings in + that post... 15:12 <@Juerd> kane_: Hmmm... use Acme::Comment qw/start q{ end };/ wo +uld work, wouldn't it? :)

    - Yes, I reinvent wheels.
    - Spam: Visit eurotraQ.
    

      or:
      <<'comment'; .... .... .... .... comment
      timtowtdi :)

      cLive ;-)

      --
      seek(JOB,$$LA,0);

        Surely they're not quite the same? Acme::Don't's don't {...} is documented as returning undef. When used as the last line of a module, don't { 1 } isn't (sorry) the same as
        <<'comment' 1 comment

Back to Reviews

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: modulereview [id://165585]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2014-09-15 02:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (145 votes), past polls