2

Background information:

I asked here 'Edit on answer got rolled back. Did I do something wrong?' if my edit to the answer was a correct/good one that got rolled back. The edit I did was to add indents and semicolons to the JavaScript code.

The semicolons don't do much in JavaScript code and are more or less optional (one could say personal preference) but most people say that good JavaScript code should always have them. For example, I found this question where a user asked this question 'Do you recommend using semicolons after every statement in JavaScript?'

For the indents, I can't find an example where it says that you also can use no indents but I find many many sites where code with no indents is used as 'bad example'.

A comment on my question did link me to the FAQ (I don't know if this is a official one) and said that

The FAQ does state that we shouldn't be making edits to code that change conventions. I'd avoid changes that are style preferences.

and got a few upvotes with this. Also many other users did say that indents/semicolons is a personally preferred style or similar and shouldn't be changed.


Information to the FAQ:

The FAQ post says in the Question part:

Do:

  • Add indentation
  • Fix syntax (non-closed brackets, missing semi-colons, etc.) if you are sure that it is not relevant to the question

Don't:

  • Change code conventions (delimited_names to camelCase names, etc.)

So from this information I get that indentation and semicolons should be added to an question and that this doesn't fall within the point "Change code conventions".

Now the relevant answer part:

This part doesn't say anything about indention or semicolon, but also has this don't part:

Don't:

  • Change code conventions (delimited_names to camelCase names, etc.)

This is the part that the comment on my question refers to. But in the Question part, indents and semicolons aren't in this point, why should they now? Also it has:

Do:

  • Improve formatting

So I guess indents and semicolon could fall within this.


Now to the actual question:

  • Are indents and semicolons opinion based and should be ignored if the user has its own convention to not use these?
  • Should I edit an answer/question just to indent it correctly and add some semicolons? (like in my edit)

My opinion (and I bet of most of the users) is that code with indents (doesn't matter if 2 or 4 spaces, a tab or something else) is more easy to read and also looks cleaner and adds to the quality of the code. The same goes with semicolons; it clearly marks the end of the line and in most languages they are also required.

11
  • 4
    I believe your original edit was fine, and was a genuine improvement on the post. Nevertheless, if the OP does not want accept the edit, is not the kind of thing one wants to escalate. This will happen to you even after your edits no longer need to be reviewed and approved. Recently I corrected the spelling in a post ("depreciation" vs "deprecation") and added code formatting to a couple of classes; and yet the post owner reverted the edits some time after...
    – yivi
    Sep 18, 2020 at 8:34
  • 2
    There are other edits (noise removal, improper use of tags, putting [tags] in the title, etc) where the rules and the problems are much simpler and clear-cut, and where one may want to spend more energy. But on certain cases, if the post owner doesn't really want someone else to improve their post, sometimes it's best simply to shake your head and walk away
    – yivi
    Sep 18, 2020 at 8:36
  • 3
    Does this answer your question? When should I make edits to code?
    – gnat
    Sep 18, 2020 at 8:46
  • 3
    The general rule of thumb is: if something is a personal opinion, don't edit it. Your opinion is not better than that of the original author. Even if "most people" agree with you, which is kind of hard to prove.
    – Gimby
    Sep 18, 2020 at 9:03
  • You did fine, but OP disagree. Without OP there would be no answer to edit and your edit is only cosmetic improvements, so let him be, forget about it and move on. Keep doing what you did, it's likely your other similar edits will stay.
    – Sinatr
    Sep 18, 2020 at 9:08
  • 1
    @gnat Thats the 'FAQ' I linked in my question :)
    – sirzento
    Sep 18, 2020 at 9:21
  • 1
    "Should I make an edit to change only indents and semicolons?" - No, you should make an edit that improves/adds indentation where it results in improved readability. You shouldn't edit existing conventions used in the code (e.g. total lack of semi-colons, 2 space indentation). You should also not make edits that only do this (which is what you said in your question), you should fix everything in the post. Sep 18, 2020 at 10:07
  • Aren't semicolons in JavaScript a trap for young players? Sep 18, 2020 at 17:13
  • 1
    The so-called duplicate says nothing about semicolons in JavaScript. Sep 18, 2020 at 17:55
  • @PeterMortensen you are welcome to rewrite the question into what it is actually asking "is adding option semicolons to JavaScript a personal preference/style or not" to get it re-opened... (I personally don't see any convincing arguments from OP that adding such optional semicolons must be requirement on SO - in general copy-paste-to-production-ready code is not a goal for SO... and even just copy-paste ready is opposed - like in recent meta.stackoverflow.com/a/401227/477420) Sep 18, 2020 at 23:21

0

Browse other questions tagged .