Maybe he's been reading this
http://mindprod.com/jgloss/unmain.html
Printable View
Maybe he's been reading this
http://mindprod.com/jgloss/unmain.html
Any convention can be made looking ridiculous by an absurd example. Can you give a real-world example where you would open more than two blocks at once (even two at once is not really a common scenario, is it?)?
If I look at a closing brace, I typically want to know what it closes, not where the corresponding opening brace is. Keeping that in mind, the K&R style is clearly superior:The last closing brace is aligned with the if statement because it closes the scope associated to it. The inner closing brace aligns with the opening brace as there is no specific construct that belongs to this block.Code:if (a == b) {
foo();
{
RAIIobject obj;
bar();
}
}
Agreed that it was a fairly contrived example....
a) Opening multiple blocks is common if you localize pre-conditions and post-contitions from functional logic.
b) Having "different rules" for starting a brace on it's own line (in your last example) is more difficult to automatically enforce (ie you need a context sensitive parser/lexical analyzer) than a simple rule of either "an opening brace always appears on a line by itself" or "an opening brace always apprears at the end of a line.
What seems logical all depends on what meanings you associate to the things in question.Quote:
If I look at a closing brace, I typically want to know what it closes, not where the corresponding opening brace is. Keeping that in mind, the K&R style is clearly superior:
If you see '}' as a terminator for the opening staement then the K&R style seems perfectly reasonable, but if you see '{' and '}' as delimiters then the other layout could be also be argued to be logical too.
I prefer this style
The reason behind i do this because is i can point to start or end of the braces to check out which braces i missed out except for single line statement.Code:if ()
{
// statement
}
else
{
// statement
}
I didn't know that breakpoint cannot be set at // statement there.
I also write line between function
// =====================
void foo()
{
}
// =====================
void bar()
{
}
This is good too.