When comparing K&R (Kernighan & Ritchie) Style vs Whitesmiths style, the Slant community recommends K&R (Kernighan & Ritchie) Style for most people. In the question“What is the best indentation style in C?” K&R (Kernighan & Ritchie) Style is ranked 2nd while Whitesmiths style is ranked 3rd. The most important reason people chose K&R (Kernighan & Ritchie) Style is:
Ensuring that control structures don't share lines with the content they define is important. Lines are the "boxes" or categories into which related syntax goes. In the case of a code block, all the syntax related to a given statement goes on the same line. This not only helps visual comprehension, but ensures that line-wise operations (user inputs like a triple-click or middle button click to select a line, delete a line, cut a line, duplicate a line, etc.) remain meaningful and effective.
Ranked in these QuestionsQuestion Ranking
Pros
Pro Consumes minimal vertical space while keeping opening/closing syntax of code blocks on separate lines from their contents
Ensuring that control structures don't share lines with the content they define is important. Lines are the "boxes" or categories into which related syntax goes. In the case of a code block, all the syntax related to a given statement goes on the same line. This not only helps visual comprehension, but ensures that line-wise operations (user inputs like a triple-click or middle button click to select a line, delete a line, cut a line, duplicate a line, etc.) remain meaningful and effective.
Pro Size symmetry between the opening/closing of clode blocks
Symmetry in size is important because it provides a visual cue that two things are similar in effect/importance. For example, in written text, lines of a paragraph are the same space apart. The space between paragraphs is larger, but also the same between each. The space between subsections, sections and chapters are progressively larger still. The space between things indicates their relatedness, and helps the reader to implicitly grasp the relationships between elements in the document.
Pro No meaningless lines avoids artificial distance between related things
Each line tells the reader something they wouldn't otherwise know, and they can therefore progress from line to line next gathering new information at each without pausing at lines which only contain a brace indicating that a code block is about to begin or just ended.
Pro No space is wasted with the opening brace
With this style, one of the advantages is that the opening brace does not take a whole line for itself, wasting a lot of space. The closing brace though is indented on the same level as the control statement it belongs to, making it easier to understand which block of code it's closing.
Pro Blocks are set apart from control statements
Like the Allman style, with the Witesmiths style the blocks are clearly set apart from the control statements.
Pro Indenting the braces makes them feel that they are subordinate to the control statement
Indenting the braces makes them feel that they are subordinate to the control statements. Which helps the reader understand which block belongs to which control statement.
Pro Easy to see how blocks of code belong together.
The fact that the code lines up up with the braces makes this by far and away the easiest style to read. The code flows much more naturally, there is zero doubt about which block the codes belongs to, your eyes are quickly drawn to what belongs where.
Pro Makes a clear divider on multi line control statements
Sometimes a control statement can take a lot of arguments and go over many lines. It frees your mind from doing the work to separate arguments and code block.
Pro Indenting Braces removes noise from the vertical line
When scanning vertically through large sections of code to review the code execution flow, having the braces indented means less noise to filter out. The execution flow statements stand alone on the vertical line and are thus far more quickly picked out by the eye.
Cons
Con May be hard to insert new lines inside statements if there are no braces
The K&R style uses braces only when necessary. So for example:
if(condition)
doSomething();
But this can be annoying if you need to put something inside that if
statement, because you have to go and add braces to make sure that will be grouped correctly with the statement that was before.
Con Hard to read when the opening statement has multiple lines
If the opening block statement has multiple lines, it really decreases the code legibility because now you have your code block mixed with the opening statement.
Con May be confusing to the eye
The braces confuse the focus of the reader's eye and this causes the reader to look longer at the line right after the opening brace and at the line right before the closing brace.
Con The closing brace does not line up with the corresponding statement
The closing brace does not line up with the statement it belongs to.