in reply to Re^2: Control Structures
in thread Control Structures

The problem with unless() is just that people get lost in double negatives and precedence. The problem with trailing if() is this.

Replies are listed 'Best First'.
Re^4: Control Structures
by adrianh (Chancellor) on May 10, 2005 at 22:42 UTC
    The problem with unless() is just that people get lost in double negatives and precedence.

    Some people do certainly but in my experience it's not a "constant sources of bugs". Certainly not enough of a problem for me to drop the improved clarity I see when the construct is used well.

    The problem with trailing if() is this.

    I'd count that a perl bug, and since perl 5.9.1 we'll get a warning for this "dubious and deprecated construct". I've never seen this in live code, and have never been tempted to write anything that looked like it. If this is the only problem then I'm not worried :-)

      I've seen it in live code, and it took a long time to figure out that was the problem. It's not worth taking the chance until Perl 5.10 is commonly used, in my opinion.
        I've seen it in live code, and it took a long time to figure out that was the problem. It's not worth taking the chance until Perl 5.10 is commonly used, in my opinion.

        I guess that's one approach. However, if it was me, and I was discovering this construct in a lot of code, then I'd write a test to go scan for it and warn me if it crept into the codebase - and train the developers to avoid the broken construct.