13

Some people like to put the open { bracket on a separated line, e.g:

if(...)
{
    //...
}

Is editing this code by merging the first two lines into single one rude?

8
  • I hope this is not a dup, I failed to find any with this query
    – ajax333221
    Commented May 21, 2012 at 22:34
  • Did you have a specific edit in mind? Commented May 21, 2012 at 22:38
  • 9
    This falls into the category of "trivial edits" because you're not substantively improving the post. I don't think it's "rude", but it's certainly to be discouraged.
    – Cody Gray
    Commented May 21, 2012 at 22:39
  • 6
    it will be funny if someone did that with this example n_n
    – ajax333221
    Commented May 21, 2012 at 22:40
  • 1
    It was funny. Now it's even funnier!
    – Shog9 Mod
    Commented May 22, 2012 at 4:16
  • 1
    @Shog9 It was not as funny as I thought... But after all, he answered my question without even submitting an answer. Well played Jacques Cousteau, well played...
    – ajax333221
    Commented May 22, 2012 at 4:18
  • 1
    I'm fine with the brackets but if(...) really is an eyesore
    – prusswan
    Commented Sep 7, 2012 at 21:46
  • 1
    Someone just did that and I reverted their change
    – CashCow
    Commented Sep 16, 2014 at 17:10

5 Answers 5

26

Is it rude? Yes. Mostly because that brace style is ugly as sin, but also because you're imposing your personal preferences on someone else's writing without good cause.

But yeah, mostly because that brace positioning style sucks.

That said, if doing so helps you trim down a code block so that it can be read without scrolling... AND you're making other substantial improvements at the same time (indentation, formatting, grammar, tags, etc.)... Then go ahead.

Related: Etiquette on editing source code formatting for style preferences

4
  • 13
    I agree that it's rude, but I don't agree with (most of) your reasoning. I have a strong personal opinion about which brace style is best. I consider changing posted code from the Bad Brace Style to the Good Brace Style to be exactly as rude as changing code from the Good Brace Style to the Bad Brace Style. (I refuse to identify which is which; everyone reading this comment may assume I agree with them.) Commented May 22, 2012 at 1:57
  • 6
    Of course, lots of us do @Keith. So as soon as you change it, you're guaranteed to be making it more unpleasant for someone to read. And in ajax's case, that someone will always include me ;-) But yeah - when you're reformatting the code from "I wrote this in Notepad with a broken spacebar", you can pretty much pick whatever style you want and it'll be an improvement; otherwise, first do no harm.
    – Shog9 Mod
    Commented May 22, 2012 at 2:02
  • "The author of this FAQ sees no clear advantage to adopting this approach and believes that said developers also put their curly braces on the wrong line."—JUnit FAQ
    – trashgod
    Commented May 22, 2012 at 3:10
  • But what if the language itself or their widely adopted style or naming conventions were opinionated (like changing a Java class name to PascalCase)?
    – MC Emperor
    Commented Sep 18, 2020 at 12:59
14

Rude or not it is an invitation to start a holy war.

We go to great lengths to keep brace style wars off the site. Please don't invite them on.


OTBS Rules!

3
  • What is OTBS please? Commented Sep 18, 2013 at 13:39
  • 2
    "One True Brace Style". Roughly the system used in K&R and my personal favorite. You'll find that many otherwise sensible and quite skilled programmers don't like it much. Commented Sep 18, 2013 at 14:25
  • 1
    I am one of those "otherwise sensible and quite skilled programmers [who doesn't] like it much" =P Commented Sep 18, 2013 at 14:27
10

It's generally accepted that you shouldn't do any more than

  • formatting into a markdown code block

  • if you're feeling generous, removing cruft like rogue tabs and making sure the code all lines up nicely (whilst honouring the OP's brace style)

  • where the language allows statements over multiple lines, adding a carriage return (and where required a line continuation character) here and there to reduce horizontal scroll.

  • removing excessive carriage returns between lines of code

Changing code style would be off-limits, as would doing things like turning (using C# as an example):

List<Thing> things = repo.GetThings()

into

var things = repo.GetThings()

Because now you're no longer working with the same code the OP is trying to debug.

See also:

When is it appropriate to edit someone else's code?

How far can I refactor the code in someone else's question? -

3

Don't edit just to fiddle with the braces.

However, if in the course of trying to repair severely horrible code formatting, you run the code through Lindent or your own favorite set of indent(1) arguments, and the braces happen to change, don't go to significant effort to put them back, either.

2

Generally, you'll want to leave the OP's coding style alone. Unless it makes the code overbearingly hard to read or excessively long (they do that for every single function of a rather long block of code), there's really no need to change it. The only thing you need to focus on is making sure that their indentation is correct. That extra line for the opening bracket isn't going to bother an experienced programmer who has seen it both ways many, many times.

1
  • That extra line is going to please an experienced programmer who has put it there many, many times.
    – Bo Persson
    Commented May 22, 2012 at 16:00

You must log in to answer this question.

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