Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re(4): My coding guidelines

by mojotoad (Monsignor)
on Nov 29, 2002 at 23:38 UTC ( [id://216613]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: My coding guidelines
in thread My coding guidelines

If not, why not? What do you use instead? I find not is usually the cleanest and most readable operator for all sorts of tests.

It's just a matter of taste. I'm not against using not, I just don't happen to prefer it.

You give the following example:

print "$pattern not found in $file\n" if not $found;

In this case I would use unless:

print "$pattern not found in $file\n" unless $found;

As for if (not -r $file) {...}, I typically use the bang operator (!) rather than not -- just a matter of preference, probably due to my C influences.

Matt

Replies are listed 'Best First'.
Re^5: My coding guidelines
by Aristotle (Chancellor) on Nov 30, 2002 at 18:18 UTC
    print "$pattern not found in $file\n" unless $found;
    I use unless when I expect that the print will be executed most of the time - unless the condition happens to be true. In the quoted case, I'd probably use if not, as the if highlights the fact that the message is only printed if the pattern wasn't found. Just like the way you use "if" and "unless" in English.

    Makeshifts last the longest.

Re: Re(4): My coding guidelines
by helgi (Hermit) on Dec 02, 2002 at 16:27 UTC
    I prefer never to use the ! operator if I can possibly avoid it. It is much easier for me to miss when skimming through code and my brain doesn't parse it autmoatically like it does "not".

    For much the same reason I always prefer "or" to "||" and "and" to "&&". My brain already knows how to parse these English words and I don't need to teach it new tricks.

    --
    Regards,
    Helgi Briem
    helgi AT decode DOT is

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-03-28 19:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found