Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

RE: RE: Uncuddled else?

by Nitsuj (Hermit)
on Oct 17, 2000 at 06:53 UTC ( [id://37086]=note: print w/replies, xml ) Need Help??


in reply to RE: Uncuddled else?
in thread Uncuddled else?

This is a style issue.

Both languages will ignore the usage of white space in this matter and therefore the style of "cuddling" your else's is valid in either language.

You can do however you please with your elses because the whitespace is ignored. The use of whitespace is important stylistically, as is indicated below, both uses are valid, but someone sight reading the code might miss that there is a loop at all in the first case, which begs the point that white space is still "important."

IE
while(condition){statement}

rather than

while(condition)
{
    statement
}
Really more important is that you delineate the code with tabs for readability regardless of what you do.

The } else { is a "cuddled else." It is important to note that cuddling just the else is considered mature coding style, not skipping the use of whitespace altogether. The reason behind this being that the else is really part of an if statement, not a separate statement as it appears to be when uncuddled (stylistically). This can be confusing to someone just learning coding and good style, so generally it is taught to just leave it uncuddled, so the line looks the same as it would on the if line. Cuddling just the else looks like this.

if (condition)
{
    statement
} else {    <== cuddled else
    statement
}


Just Another Perl Backpacker

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-19 20:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found