Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re^3: perlstyle - Unclear wording

by pg (Canon)
on Nov 18, 2005 at 18:04 UTC ( #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.

Comment on Re^3: perlstyle - Unclear wording
Download Code
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 ]

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.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2014-10-25 00:17 GMT
Find Nodes?
    Voting Booth?

    For retirement, I am banking on:

    Results (138 votes), past polls