Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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.

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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://509888]
[virtualsue]: holli about half
[choroba]: "Tatsächlich, das ist die Knochenstruktur eines Bettlers!" ??
shmem bows. Thank you
[marto]: slowclap.gif
[marto]: animated gif in question...
[1nickt]: Interesting article on the Coming Software Apocaplyse that I found while following one of eyepopslikeamosqui to's posts. Posits that no one can guarantee the quality of, or even understand, the 100 million lines of code in a mo
[holli]: you know, monk days are fun and all. but too many of them are bad for your health
[1nickt]: ...modern car. Suggests using TLA+ or other software modeling language to autogenerate code.
1nickt is not sure more and more layers separating the programmer from the program is the right way to go...
[holli]: happy one, shmem ;)

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (12)
As of 2017-11-21 12:56 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (301 votes). Check out past polls.