Monday, May 20, 2024
186
rated 0 times [  193] [ 7]  / answers: 1 / hits: 35239  / 14 Years ago, sat, july 10, 2010, 12:00:00

At work, we place braces on the next line, but at home, I do the opposite. Which one do you prefer? (K&R vs OTBS)



function something() {
// ...
}

function something()
{
// ...
}


A lot of JavaScript libraries seem to use the OTBS (one true brace style). I'd like to follow them for consistence among other JavaScript projects, but doesn't K&R style look more readable?



Note: We know the problem with return and braces in JavaScript, that will always be an exception. However, that is only a single case.


More From » coding-style

 Answers
-1

This is a Holy War to which you will never get a usable answer! Just stick with whatever everyone else in the project is using and don't argue!



For what it's worth, I'm a K&Rite. I find the OTBS puts a lot of visual space between an opening structure and the following statement, when those two lines are often strongly related so would be better presented together, without an intervening almost-blank line. I like to keep my blank lines reserved for separating blocks of related statements.



In a coding style which a lot of whitespace anyway, this may be relatively unimportant. But personally I value terseness, so I can keep more of the program on-screen.



I don't buy that having the open-brace on a different column to the close-brace is an issue. It's still easy to see the block shape just from the indents. Unless you're using hanging indents. Don't do that. But that's another Holy War entirely.


[#96282] Wednesday, July 7, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
leog

Total Points: 225
Total Questions: 113
Total Answers: 118

Location: Oman
Member since Wed, Apr 12, 2023
1 Year ago
;