Search code examples
javalayoutcurly-braces

Where should I place braces?


I was wondering if I should place my braces like this

for(int i = 0; i < 10; i++){

}

or should I place them like this?

for(int i = 0; i < 10; i++)
{

}

witch one is "better" or more common ?


Solution

  • This is subjective issue, not objective, and therefore not a suitable question for Stack Overflow.

    Pro tip: If you're working on a team, your team should have agreed on a style that will be consistently used through all source files. Adhere to it. Don't be the guy that opens other people's files, changes the format to your preference, and then commits back to the repository. Dick move there, and grounds for firing IMO.

    Advanced pro tip: Spend your time worrying about things that actually matter. An unbelievable amount of blood has been spilled in the programming community arguing over garbage like this.

    Super-advanced pro tip: The one true brace style, and the right way to place braces, is on the same line as in your first example. This is also the guideline recommended by the Java code conventions. 😄