Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^3: perlstyle - Unclear wording

by pg (Canon)
on Nov 18, 2005 at 18:04 UTC ( [id://509888]=note: print w/replies, xml ) Need Help??


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

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.

Replies are listed 'Best First'.
Re^4: perlstyle - Unclear wording
by Aristotle (Chancellor) on Nov 19, 2005 at 04:28 UTC

    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.

Re^4: perlstyle - Unclear wording
by halley (Prior) on Nov 18, 2005 at 21:00 UTC
    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 ]

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-19 14:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found