Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: My coding guidelines

by Abigail-II (Bishop)
on Nov 26, 2002 at 10:47 UTC ( #215817=note: print w/ replies, xml ) Need Help??


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

Don't say always too fast. Are you sure you always snug unary operators? Including not?

Abigail


Comment on Re: My coding guidelines
Download Code
Re: Re: My coding guidelines
by mojotoad (Monsignor) on Nov 26, 2002 at 17:22 UTC
    Since I never use 'not' in my code ... yes. ;)

    I take your point, however -- there are indeed exceptions. I think "english language" unary operators might be a whole class of exceptions since they parse (to us) as English rather than code.

    By the way, why is '->' a binary operator? From perldoc:

    "->" is an infix dereference operator, just as it is in C and C++. If the right side is either a ..., {...}, or a (...) subscript, then the left side must be either a hard or symbolic reference to an array, a hash, or a subroutine respectively. (Or technically speaking, a location capable of holding a hard reference, if it's an array or hash reference being used for assignment.) See perlreftut and perlref. Otherwise, the right side is a method name or a simple scalar variable containing either the method name or a subroutine reference, and the left side must be either an object (a blessed reference) or a class name (that is, a package name). See perlobj.

    Seems like dereferencing is dereferencing is dereferencing, no RHS required. Is there an association going on as well?

    Matt

      You wrote:
      Since I never use 'not' in my code ... yes. ;)

      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.

      die "$usage" if not @ARGV; if (not -r $file) { die "Cannot read $file\n"; } print "$pattern not found in $file\n" if not $found;
      And so forth.

      --
      Regards,
      Helgi Briem
      helgi AT decode DOT is

        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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (11)
As of 2014-11-28 08:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (194 votes), past polls