Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: perlstyle - Unclear wording

by Corion (Patriarch)
on Nov 18, 2005 at 13:55 UTC ( [id://509776]=note: print w/replies, xml ) Need Help??


in reply to Re: perlstyle - Unclear wording
in thread perlstyle - Unclear wording

Sumsumming the other ideas that were floated on the CB

There are many situations that seem to apply but don't make sense:

if ( ($foo == 1) and ($bar == 1) ){ # ^ space after last matching parens

Also, in plain statements, it doesn't make much sense:

(caller) [0] # ^ space after last matching parens?

Replies are listed 'Best First'.
Re^3: perlstyle - Unclear wording
by TimToady (Parson) on Nov 18, 2005 at 18:11 UTC
    Yes, it would be clearer if it said something like "Space between two right parens when the first matches a left paren on the current line and the second matches a left paren on a previous line."
Re^3: perlstyle - Unclear wording
by pg (Canon) on Nov 18, 2005 at 18:04 UTC

    I agree that those cases don't make much sense. But with long and complex condition statement, I occassionally break it in some way to help myself understand it, for example:

    if (($a1 == $a2) && ($a3 == $a4) && (($a5 == $a6) || ($a7 == $a8)) ) { }

    This way of breaking makes it clear (at least to me) that those lines are at the same level.

      FWIW, I prefer to treat all paired delimiters the same (ie parens, brackets and braces all follow the same rules). When I break a single expression over multiple lines, I put the “connecting” ops at the front of the new line, instead of hanging them off them end of the previous one. And I use whichever set of boolean ops require the fewest parens (usually, the low-precedence ones) – in fact I always aim for the fewest paired delimiters possible, and only add optional ones deliberately when the result is too uniform and devoid of visual hooks. In this style, your example would be:

      if ( $a1 == $a2 and $a3 == $a4 and ( $a5 == $a6 or $a7 == $a8 ) ) { # ... }

      Makeshifts last the longest.

      Of course, the spelled keywords 'and' and 'or' help de-parentheficate this sort of thing slightly:
      if ( $a1 == $a2 and $a3 == $a4 and ($a5 == $a6 or $a7 == $a8) ) { }
      For readability, I also pull some tests into literate (readable, self-documenting) boolean names: my $nouns_match = ( $a3 == $a4 ). Then I can just refer to $nouns_match in the complicated conditional.

      --
      [ e d @ h a l l e y . c c ]

Re^3: perlstyle - Unclear wording
by eric256 (Parson) on Nov 18, 2005 at 14:45 UTC

    Ahh. For what its worth. When it said matching I though the expresion part of an if block. Although looking at those, the wording isn't very clear.


    ___________
    Eric Hodges $_='y==QAe=e?y==QG@>@?iy==QVq?f?=a@iG?=QQ=Q?9'; s/(.)/ord($1)-50/eigs;tr/6123457/- \/|\\\_\n/;print;

Log In?
Username:
Password:

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

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

    No recent polls found