Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: My coding guidelines

by mojotoad (Monsignor)
on Nov 25, 2002 at 18:12 UTC ( #215684=note: print w/ replies, xml ) Need Help??


in reply to My coding guidelines

Excellent list. It's not often you see style guidelines along with some informative prose as to the why of the guidelines.

I was surprised by this part (24):

Note that there is whitespace between ++ and -- and their operands, and between -> and its operands.

What's the consensus on this one? I've always liked snug ++/-- and dereferencing:

++$wolverines; $rabbits--; $wombat->move(); $turtle = $menagerie->[4];

As opposed to:

++ $wolverines; $rabbits --; $wombat -> move(); $turtle = $menagerie -> [4];

For that matter, I've always made unary operators snug so that you can immediately find it's operand. This might be a holdout from C, but I do actually find the snug form more aesthetically pleasing.

On a somewhat visually related note, the arrow form of the left-associative operator works well with whitespace, however:

%myhash = ( lizard => 'gecko' );

Whereas the equivalent comma operator is snug with the left operand.

Thanks again for the list,
Matt


Comment on Re: My coding guidelines
Select or Download Code
Replies are listed 'Best First'.
Re: My coding guidelines
by Abigail-II (Bishop) on Nov 26, 2002 at 10:47 UTC
    Don't say always too fast. Are you sure you always snug unary operators? Including not?

    Abigail

      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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2015-07-30 02:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (269 votes), past polls