in reply to Uncuddled else?

It has been said that the perl style is:
if ( some condition ) { print "It's true\n"; } else { print "It's false\n"; }
I think a far more readable style would be:
if ( some condition ) { print "It's true\n"; } else { print "It's false\n"; }
Why am I proposing such a heretical thing, with the "else" starting on a line by itself, and being indented the same as its matching "if"? Simple - extend the statement to:
if ( Some condition 1 ) { print "First case\n"; } elsif ( Some condition 2) { print "Second case\n"; } else { print "Default case\n"; }
See - each clause of the compount if-elsif-else structure is logically (imho) aligned.

Replies are listed 'Best First'.
RE: RE: Uncuddled else?
by doran (Deacon) on Oct 17, 2000 at 02:15 UTC
    I agree that it makes more sense (to me, at least) to do as you illustrate. In fact on pg. 547 of The Camel Book, Ed.2 it says:
    • Put a newline between a closing brace and else
    So I've always done it that way.