Question

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 ?

Was it helpful?

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. 😄

OTHER TIPS

The former the preferred syntax from Oracle's Java Code Conventions:

http://www.oracle.com/technetwork/java/javase/documentation/codeconvtoc-136057.html

Specifically:

http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-142311.html#454

And thus is relatively common. In general: pick a coding convention (as a team, if it's a team) and stick to it. What is now Oracle's conventions were basically the original, for Java, and thus fairly commonly adopted, at least as a starting point - but you're free to whatever you prefer (as a team / company / etc.).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top