Note: I'm not sure if this is the right place for this. If another site suits this question better, please point me there. I was going to place it on cs.SE, but there was no tag about formatting, so I figured it didn't belong there, and this isn't actually runnable code, so I figure it doesn't belong on codereview.SE either.
When I was first taught to program in Java in 2009, my teacher (and all the examples from the book) had the code formatted as such:
public void method()
{
if (condition)
{
doStuff();
}
}
However, in the field, I rarely, if ever, see it like that. Almost always, it's like this (whether or not it's Java code):
public void method() {
if (condition) {
doStuff();
}
}
Why do so many programmers choose to put the curly braces on the end of a line instead of their own line? Is it to save scrolling length or file size? Perhaps it was the standard before my education? To me, it just makes it less clear whether we're entering a new block.
Of course, I can chock up doing things like how many spaces to indent or adding spaces within parentheses, like if ( condition )
, to personal preference, since it's not done nearly as often, but placing the brace at the end seems to happen way too often to just be personal preference.