What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 134 Stack Exchange communities.

I'm torn on this question here.

It's basically asking whether it's a good idea to have the opening brace of a code block on its own line or as part of the if/while/etc line that the block belongs to.

Now normally I wouldn't worry too much but the question specifically asks for the reasons why one way is better than another.

And having gotten hit in the head this morning by my 6yo son's hockey stick, I'm feeling unusually philosophical.

It appears to me that this is no different to a question like:

I have some data which is mostly sorted, which sort algorithm is fastest when adding small sets (three elements or less) to it, and why?

Now that either has no single 'right' answer since there are a myriad of sort routines that would be up to the task, or it has a right answer depending on the pros and cons given in the answer. I think I would probably let that one go and see what answers were generated since algorithm selection in specific cases is of interest to me.

But I can't really discern a difference between that and:

Is the opening brace for an if statement better on the same line or next line, and why?

but that may just be the concussive effects from that curved indentation in the side of my head.

I'd be inetersted in knowing what people think about it.

share|improve this question

5 Answers 5

up vote 4 down vote accepted

That should be reopened and closed as exact duplicate of following locked question.

Open brace on the same line as the if or on the next line?

share|improve this answer
3  
Doing my part to reopen. Someone ping me when it's time to close it again. –  mmyers Jun 26 '10 at 5:17
1  
It's reopened. Time to close it again. –  lc. Jun 26 '10 at 6:33
    
@mmyers, pinging, now can close as exact dup. –  YOU Jun 26 '10 at 6:40
    
Thanks, voted to close. –  mmyers Jun 26 '10 at 6:59
1  
Its now closed properly. –  Tim Post Jun 26 '10 at 8:38

Brace style wars are the very exemplar for subjective and argumentative.

People have been shouting at one another about this topic since the seventies, its as bad as emacs vs. vi. So, YES it should be closed as S&A, as should all the duplicates.

Oh, and by the way, if you don't use the One True Brace Style you are a blaspheming heretic and bound for the fiery depths.

share|improve this answer
    
emacs vs. vim!!!!1111oenoneone!! –  Ether Jun 27 '10 at 17:08

If we could somehow ensure that the answer was, "C is whitespace-agnostic, so put 'em wherever you damn well please" then yeah, it'd be a nice question to have around for newbies.

Of course, we already have at least one like that... And apparently, it's one of those topics that some folks just can't help but respond to, even when they've nothing useful to add to what's already been said.

I'm tempted to re-write it as, "Does it matter where I put my braces?" and see if it still collects more than one or two answers...

share|improve this answer
    
Well, that would be your answer but that doesn't necessarily make it the right answer :-) However, since I asked for thoughts, I guess this meta-answer as good as any other. I would mention two things however. The question you reference was also closed S&A so this meta discussion still stands. And your question "does it matter" is not the same as that referenced. Yours has a specific answer, "no, unless you put them in a totally different file" :-) It's not subjective at all. –  paxdiablo Jun 26 '10 at 4:34
    
Yes. If they're dental braces, they should be placed on your teeth, preferably by a orthodontist. If they're orthopaedic braces, they should be placed where directed by a physician or physical therapist. –  waiwai933 Jun 26 '10 at 4:45
    
@paxdiablo: point is, everyone's got an answer - that's what makes it subjective! And there are three other S&A-closed questions linked to from the S&A-closed question linked to in the S&A-closed question you linked to... It's an extremely common question. I suspect it's common because - even though it could be asked in a non-subjective way (supposing you missed the bit in the first chapter of your language reference that answered it for you) - a new user will naturally encounter all manner of brace and whitespace combinations, and start to wonder if he didn't miss something important. –  Shogging through the snow Jun 26 '10 at 4:50
1  
Okay, by that reasoning, all of the 'best practices' questions are also S&A since there are multiple valid answers. I'm pretty certain they should be allowed to survive. I have no issue with closing it as a dupe if it is. But S&A I'm not sure of, unless all such questions are treated as such. I'm not trying to be argumentative here (although that may be such a basic personality trait that I can't prevent it) so sorry if it comes across that way, I'm just seeking comments/advice from others. –  paxdiablo Jun 26 '10 at 5:16
    
@paxdiablo: it's cool - this is one of those endless discussions that'll probably still be going strong long after SO is dead and forgotten. Heck, I've seen the same people arguing both sides of it. When is a question S&A and when is it merely subjective? I don't really think there are any good rules, and the "best practices" questions are a good example: some of them do manage to reach a sort of consensus, while others remain quarrelsome. And some topics - indentation, "best [language|editor|construct]" - have a reputation for the latter. –  Shogging through the snow Jun 26 '10 at 8:09

It appers to me that this is no different to a question like:

I have some data which is mostly sorted, which sort algorithm is fastest when adding small sets (three elements or less) to it, and why?

I see a large difference there: the choice of a sorting algorithm in a particular situation can have a significant effect on how a program runs, moreover, an effect that actually matters. It can be the difference between slow and fast execution. In a commercial product it could make or break sales. In a web application, the wrong choice could cause people to give up on the site and go elsewhere - again potentially costing sales if it's an e-commerce site.

On the other hand, where you put your braces doesn't make a bit of difference to anybody, except yourself and maybe other coders who work on the same source code. There's really no valid reason to care one way or another, besides personal preference.

share|improve this answer

The correct answer to this question depends on whether your trousers have buttons for braces or not.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .