24

I came across an edit that only added a language to the code block, i.e.

``` > ```java

After looking around, I found this answer which suggests yes, always, as long as it's the only thing that needs fixing, but also this one, which suggests maybe?

There was also a change of brackets, i.e.,

bracketsOnTheNextLine()
{
  // this was genuinely hard for me to type
}

to this:

obviouslyTheWriteWayToDoIt() {
  // but it wasn't what the author wrote
}

So I decided to skip it. Then the same user turns up again in my queue with the same type of edit (added a language and changed the white-space) and I noticed the user has a habit of doing this, with 95% of their edits over the last couple of weeks being "using code tags".

If it were a tag or a typo, I'd agree that it's an improvement, even if only trivial, but changing the code-style and/or adding a language tag is (I'd argue) another degree into triviality.

Should I accept it because it's right and they'll cap out eventually, or should I reject with the hope it discourages such trivial edits?

More answers on the topic:

The first example:

Edited code in example one

The second:

Edited code in example two

16
  • 1
    Also: When should I make edits to code?
    – yivi
    Commented Oct 28, 2020 at 8:41
  • 16
    If these were the only changes, (and the language hadn't already been correctly detected via tags or some other magic), I would absolutely reject them. There's no need to explicitly specify the language if it's already correctly inferred Commented Oct 28, 2020 at 8:43
  • 3
    why didn't you show us the link, also there i a decline optin for unnecessary edits
    – nbk
    Commented Oct 28, 2020 at 8:43
  • 7
    If the syntax-highlighting was not being correctly applied (which happens sometimes), it's not a bad edit on itself. Changing code-style is a grayer area. The kind of edit you describe (two equally legible ways of writing code, simply adhering to different styles), is logically redundant. I imagine the error in "the right way to do it" is simply that, and not intended to be part of the question, right?
    – yivi
    Commented Oct 28, 2020 at 8:48
  • 1
    @nbk I'm not in the habit of calling people out. Also, the question is whether it is unnecessary or not.
    – Druckles
    Commented Oct 28, 2020 at 9:13
  • 1
    @yivi I've added screenshots for your viewing pleasure :-)
    – Druckles
    Commented Oct 28, 2020 at 9:13
  • 5
    Looking at the examples given (assuming no more edits in the posts and that syntax highlight was already correctly inferred, which the suggested edit preview is often awful at showing), I'd reject both as superfluous/no improvement. Commented Oct 28, 2020 at 9:15
  • 3
    Admittedly, there are cases where this is not just necessary, but required. Auto-detection of language is pretty horrible after the migration to highlight.js Commented Oct 28, 2020 at 11:54
  • 1
    @Druckles from your description it seems an unnecessary edit and yu can declined it, but when you are searching for guidances, we need to know if your opinion is accurate, which we don't can as you didn't post the url to the question. So in short deline it when not improvig the question/answer or give us the example
    – nbk
    Commented Oct 28, 2020 at 15:15
  • @Druckles as nbk says, by refusing to link to the reviews that you find problematic, you are preventing anyone else on Meta from inspecting them to determine additional context that may well influence their answer or further actions (e.g. have a mod contact the user). That's effectively the same as posting a question that lacks code, and such questions are closed for good reason. If you are concerned that the Meta effect will unfairly punish the user in question, remember that you are not responsible for others' actions.
    – Ian Kemp
    Commented Oct 28, 2020 at 16:01
  • @Nick do you mean to say if the language had already been correctly detected?
    – Sellyme
    Commented Oct 29, 2020 at 2:37
  • "There's no need to explicitly specify the language if it's already correctly inferred" The problem is, the code for language inferencing changes over time. Just because it was inferred correctly today doesn't mean it will be next year. I'd definitely vote for explicit settings. Commented Oct 30, 2020 at 2:09
  • Line breaks in code are subjectively determined (you could have code that doesn't have any line breaks, but that would be too hard to read for other people), so if it's not like the edit made some hard-to-read code easier to read, I think these edits should be rejected. Commented Oct 30, 2020 at 13:34
  • @Zoe not a fan of the new syntax highlighter then?! :)
    – Caius Jard
    Commented Oct 30, 2020 at 17:28
  • "Obviously the right way to do it" Hmmm, not for a C# guy. I code more like the left upper part. And I agree with the first link that sais if it was the only thing to be fixed to reach perfection than do it. If you're editing ONLY this while there are many other things to edit, that's bad. Commented Oct 30, 2020 at 17:55

2 Answers 2

29

The site should pick the correct code formatting based on tags. So if someone felt a need to add ```java then maybe the true culprit is the missing tag. If so, the correct edit is to add that tag. Always check if the question seems correctly tagged when doing reviews.

Otherwise, in the somewhat rare case where the language is for some reason not clear, like for example a question about porting from Java to C# with multiple language snippets in the same question, it may be appropriate to add manual code formatting tags and edits doing so should be approved.

Edits adding code formatting to code that lacked formatting should be approved.

Changing bracket coding style is not an OK edit. Same thing with changing between 2, 4 or 8 space indention (though 8 is pretty rare and awkward). This is 100% subjective and editors who change coding style only achieve two things: annoy the OP and waste everyone's time. Unless they harmfully manage to add bugs that weren't there to begin with. As a rule of thumb, reject such edits - too minor, no improvement whatsoever.

4
  • 5
    Unfortunately, giving a post a tag only helps if the post has no tags associated with languages currently. If the post already has a tag associated with a highlight language, adding another tag (like Java) is likely to make things worse unless one also manually styles each code block with the right language, see meta.stackoverflow.com/q/401573 for details. Commented Oct 28, 2020 at 14:07
  • 5
    "The site should pick the correct code formatting based on tags" emphasis on should. It hasn't in the past and the new prettifier is far from perfect either, so I always manually specify the language I'm using. Further, "let the tag determine the language" falls over completely when you have multiple languages in the same post.
    – Ian Kemp
    Commented Oct 28, 2020 at 15:50
  • 4
    Changing bracket coding style is an OK edit if the OP has no bracket style, e.g. no indentation whatsoever. Commented Oct 28, 2020 at 19:48
  • 1
    Another case where just adding the language can matter: TypeScript posts. The default formatting language for the TypeScript tag is JavaScript, despite the fact that highlight.js does a better job highlighting TypeScript when it knows it's TypeScript. So adding lang-typescript (with the lang- prefix) can improve the formatting of the code. Related FR here. Commented Oct 30, 2020 at 13:14
17

If the language isn't correctly being detected and the wrong syntax highlight is being applied I consider that adding the language code to the source fence is a valid edit.

Two relevant examples:

  1. A post that mixes HTML, JavaScript, plus some specific templating language, together with a stacktrace will require 4 different language codes. Choosing the correct language codes is already a copy-editor skill, and readers will want the correct syntax highlight applied.

  2. A Python post that mixes source code with interpreter execution can be written using two different syntax highlights. I'd be inclined to applaud a copy-editor that takes these subtle differences into account. There are a couple of very good posts on the subject, "Should I prefix example Python code with “>>>” to indicate running in the interpreter?", "Syntax highlighting language request: Python REPL"

After looking around, I found this answer which suggests yes, always, as long as it's the only thing that needs fixing, but also this one, which suggests maybe?

Well it depends if the syntax highlight is being correctly detected. A change in tags can change language detection, hence a code fence with language code is a safer option because it leaves no room for language auto-detection mistakes.

If syntax highlight is already being correctly detected I would not risk approving that edit myself. In that case the edit will have no practical effect and can be considered redundant.

There was also a change of brackets, i.e.

The 2 examples you gave are formally completely equivalent, I would not approve such an edit but if overhauling a post I might change the brackets if it avoided the source fence getting a scroll bar. The reason being is that it will save the readers an option of having to scroll the source fence instead of getting it "at a glance". I would not approve an edit on that reason alone, but if taken together with other minutiae I would consider it a formatting plus.

P.S. At the time of this writing syntax highlight does not always work in edit preview and suggested edits queue. So I would double check if adding the language code in a suggested edit does indeed, or not, correct language highlighting.

You must log in to answer this question.

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