When I post code, I deliberately format it the way I want it to appear. Sometimes someone comes and edits my post just to change the source code formatting style to suit their preferences (e.g. for use of whitespace). I don't care for that.

  1. A big part of the incentive for me to post here is to demonstrate my knowledge and get credit for it. Source code formatting is important to me, and since people will draw conclusions about my skills and style from looking at my posts, I want the code in my posts to show my style. So it annoys me when someone reformats my code (if I thought it was an improvement, that'd be one thing, but I'm talking about cases where I prefer the original). (I know people could see how I originally posted it if they looked at the revision history, but how often is anyone going to do that?)

  2. I'm not in the habit of editing code in the posts of other knowledgeable users just to conform to my own style preferences, but when I include code in my posts I certainly want it to convey my style preferences. I'm not only showing how I do it, I'm advocating that style and suggesting it to those who see it. When I'm answering a question, it's part of the information / advice I'm offering.

When I copy a code example from someone else's post, modify it, and include it in my post, I often reformat the version in my post according to my preferences, for the reasons mentioned here. But that's a big difference from changing it in the original post. When someone who knows what they're doing posts code, if it's fair game for anyone to edit it (in the actual post) just to conform to their style preferences, where would it end? If people edit my posts to conform to their preferences, and I were to edit theirs to conform to mine, what sense would that make?

What is the etiquette on this? Is there any mechanism for rejecting edits to your own posts? When this happens, should I just feel free to go back and revert the post to my version?

  • 9
    In my opinion, the edits made the code much more readable so I'd say they were valid. – simchona May 2 '12 at 17:48
  • 2
    I propose the commandment Thou shalt not instigate the Brace Style Wars. – dmckee --- ex-moderator kitten May 2 '12 at 17:52
  • 6
    Formatting like that would get you a serious talk if you were working with me... Are we seeing the same? Here's a screen capture of what I see. Also, aren't you using a code formatter? I don't think I've never seen an option to have one add blank lines after each and every statement. – Arjan May 2 '12 at 17:53
  • 3
    Still, when not talking about your style, I think it's a valid question, so +1. (As an aside: voting is a bit different here.) – Arjan May 2 '12 at 17:59
  • @simchona, exactly, in your opinion -- that's what makes it a preference. This is one specific example -- what if the specific versions were reversed? – JMM May 2 '12 at 18:04
  • @Arjan: While I actually agree with you, it leaves us in the position of saying "Well, some style edits are good and some are not so good." and we land a subjective mire from which we can only be extricated by the blunt instrument of majoritarianism. ::sigh:: – dmckee --- ex-moderator kitten May 2 '12 at 18:04
  • @Arjan, almost -- your screencap made me notice that I had a mistake (some lines indented 4 spaces that were meant to be 2). Here is what I meant to have. That's your preference and you can give a talking to about it to people who have to listen to you :) What do you mean a "code formatter"? An editor? I press Enter when I want a newline. Thanks for mentioning the voting, I did not realize that. People seem to be focusing on this example / my style rather than the concept. – JMM May 2 '12 at 18:08
  • 1
    @JMM Because the concept is too general; the answer to your question is "maybe" – Michael Mrozek May 2 '12 at 18:17
  • 8
    But, @dmckee, not all coding styles use almost twice as much vertical space as others... ;-) – Arjan May 2 '12 at 18:17
  • 4
    @JMM If the versions were reversed, I would argue then the edit was invalid because it makes the question/answer much harder to read. – simchona May 2 '12 at 18:18
  • @JMM, for example in Eclipse I press Shift-Command-F to auto-format. – Arjan May 2 '12 at 18:19
  • @Arjan, oh, ok, thanks. No, I didn't use that. – JMM May 2 '12 at 18:23
  • I normally only edit code when someone has made it totally unreadable, no spacing or everything on the same line. However I very rarely code in JS at all and was really tempted to start removing whitespace in your fiddle... – ben is uǝq backwards May 2 '12 at 18:27
  • @Ben, since it won't have my name on it, and I won't have to try to read it later, knock yourself out. – JMM May 2 '12 at 18:31
  • 8
    @JMM, if you're going to post pointlessly double-spaced code, you should be thanking the person who's kind enough to edit it to a reasonable length for you. – Kyralessa May 2 '12 at 21:29

The edit was primarily in reducing the number of empty lines.

Screen real estate is still something to consider and in my opinion the editor made a good edit - more of the code is visible and can be read together with the rest of the question.

Too much whitespace is something that reduces readability.

  • 5
    I agree with this analysis of the specific case, however, the editor also removed spaces between braces and parentheses. Some people much prefer a few extra spaces: print( "stuff" ) ; vs. print("stuff"); and this has little to no effect on real estate unless the lines are too long. – Kevin Vermeer May 2 '12 at 18:26
  • 7
    It's hard to criticize someone for making a few tweaks like that when the formatting of the original code was so egregiously bad. If someone edited only to remove spaces between parens and the like, it'd be a different story. – Kyralessa May 2 '12 at 21:32
  • 1
    "Too much whitespace is something that reduces readability." -- I much more commonly find readability hindered by too little whitespace. "and in my opinion the editor made a good edit" -- you realize that's not actually the question, right? "Screen real estate is still something to consider" -- what do you mean, for mobile devices? – JMM May 3 '12 at 21:31
  • @JMM - Too much or too little... all in the eye of the beholder. – Oded May 4 '12 at 8:21
  • @JMM - In regards to screen realestate, not only mobile devices (which are certainly gaining more traction on the web), but not every developer out there has two screen or very high resolution screens. – Oded May 4 '12 at 8:22
  • "Too much or too little... all in the eye of the beholder." -- right, which is why people probably shouldn't meddle with other peoples' over such subjective standards. "but not every developer out there has two screen or very high resolution screens." -- I currently have a viewport height of 670px, which isn't terribly high, and I'm not having any trouble with it. In fact, in this specific case (which everyone was so fixated on), even with the font size bumped up 2 steps I can see the entire code example, and the preceding paragraph to boot, without even scrolling. – JMM May 4 '12 at 12:49
  • In any case, vertical scrolling is an inevitable part of using computers, let alone developing software. I'm a lot less concerned about people having to scroll a little than I am about them going and writing a bunch of ugly, unreadable code. If there are really compelling arguments for a need to compress the on-screen footprint of code, that's something I'd be willing to take into account, but most people seem to just be complaining that they don't like it, to which I say, that's not what I asked. – JMM May 4 '12 at 12:50
  • What's really hilarious is that everybody approves of the edit because they found the original so repulsive, but while the editor stripped out newlines and changed the horizontal spacing around braces / parens (which could probably start a holy war among those here who all agree about the newlines), they didn't fix the one thing actually wrong with it -- mismatched 2 / 4 spaces of indentation (OP's original code had 4, and I missed it when I copied it and reformatted for my post). I also wouldn't be too surprised if the editor's primary motive was to make the formatting resemble the OP's more. – JMM May 4 '12 at 12:50

The answer is, if you don't like the formatting of some code, feel free to edit it solely to reformat it according to your preferences for style / improved readability (especially if it contains a reprehensible amount of vertical whitespace). Implicitly, this means that you can feel free to revert such edits that people make to your code.

You must log in to answer this question.

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