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
tocamelCase
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
tocamelCase
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.