[UKLUG] Re: LPM: unless ($line =~ /^#/)
Rich Bowen
rbowen at rcbowen.com
Tue Jan 2 08:26:12 CST 2001
> > Unless may be great for throw-away programs, where you're trying to code
> > quick, but as you can always negate the test in your condition, it's
> > normally easier to maintain when you always use 'if'.
> >
> > Besides, it's fewer keystrokes to type:
> >
> > if ($line !~ /^#/)
> >
> > vs.
> > unless ($line =~ /^#/)
> >
> > -----
> > Joe Hourcle
>
> If the boolean expression is that simple, you're probably right. If the
> if clause is more complex, then I think the unless is often more
> readable:
>
> if (not($hairy_compound_boolean_expression)) {
>
> vs.
>
> unless ($hairy_compound_boolean_expression) {
>
> That removes a set of parentheses and should still be readable.
> Assuming there's no else at the end of it though, because the else would
> give a better opportunity to clarify.
Particularly when you are doing statement modifiers, unless leads to
very consise and readable code.
next unless $line;
Which would be cumbersome using if.
--
Rich Bowen -- Director of Web Application Development
http://www.cre8tivegroup.com/ -- rich at cre8tivegroup.com
Have trouble remembering things? http://www.idforgetmyhead.com/
More information about the Lexington-pm
mailing list