0
Something about braces in java
I really want to know the proper use of braces in my source code
1 Respuesta
+ 5
It all depends on who you ask, with how to write them in Java, or in any language, really. Some people try to minimize the number of lines they take up, some (like me) give all braces their own lines so they align neatly. There's also people who don't write them if they aren't needed (ex: ifs with one line).
For methods, ifs, fors, whiles, etc., I write the header, and put the braces beneath at the same number of tabs in:
while(/*whatever*/)
{
if (/*something*/)
{
}
}
do/while is an exception, where the last brace and while are on the same line. It's so the while footer isn't confused for a separate empty while:
do
{
} while (/*whatever*/);