Tuesday, September 25, 2007

Why it is important to cuddle your braces when writing code

The Fundamental Theorem of Formatting states that the visual layout should show the logical structure of the program. As Steve McConnell says in his classic Code Complete the coding style where opening braces occur alone on a line beneath the conditional or loop statement they belong to (that if one is allowed certain liberties with the meaning of the word "style") violates this principle in that it suggests that the body of the conditional or loop is subordinate to the brace, rather than the for or the if statement that it belongs to!