50

Just looking at this question. I've seen a few questions in this format lately where new(er) users are using code snippets to format their questions rather than the traditional four space method. These questions are then cluttered with "Run This Code Snippet" buttons (which either just display the text again or simply do nothing) which detracts from and confuses the question.

So should they be edited or be left as they are?

Edit: Ok, the question has been edited while I was composing the question so at least one person thinks they should!

5
  • 5
    Especially if they're showing not runnable code, they should be edited out. Not so sure about your example, since it's about javascript. Commented Sep 24, 2015 at 12:42
  • 2
    @πάνταῥεῖ: In that example, there is no point in running the code. So, snippets shouldn't be used.
    – Cerbrus
    Commented Sep 24, 2015 at 12:44
  • 1
    You'd think that the "HTML/CSS/JS/Result" boxes would discourage people from doing it... Commented Sep 25, 2015 at 18:36
  • @nietthedarkabsol You'd think so but even in the javascript and jQuery tags I see them mis-used pretty regularly.
    – John C
    Commented Sep 25, 2015 at 19:14
  • I once suggested adding at least a warning in cases when snippets should not be used.
    – PM 77-1
    Commented Sep 25, 2015 at 19:52

3 Answers 3

70

Edit them

The snippet feature is of no use to posts where the code isn't meant to run. It only wastes space.

I usually also add a comment along the lines of:

"Please don't use Stack Snippets for code that isn't meant to run on your post."

Of course, make sure you fix everything you can about a post: Fix typos, remove noise, that kind of stuff, when editing out snippets.


Simply put:

Snippets should only be used for JS / HTML / CSS posts where running the code helps in showing the solution / question.


For example:

This answer of mine about generating tables has a snippet to show the code generating a table.
The snippet provides direct visual feedback about what the code does, while it doesn't require any extra code to actually show the answer.

This answer about parsing integers on the other hand, just has some code blocks. If I wanted to use a snippet there, I'd have to add a bunch of HTML and JS that really isn't relevant to the problem in the question.


In the question you linked, the difference in post length compared to the added value of the snippets (none) only illustrates to show why edits like that should be made:

enter image description here

6
  • 3
    Of course, the edit should also have fixed the 'i' to 'I' mapping, and any other problems as well as removing the superfluous snippet markup. Commented Sep 24, 2015 at 13:59
  • @JonathanLeffler: You're absolutely right. I added that to my answer.
    – Cerbrus
    Commented Sep 24, 2015 at 14:11
  • 1
    A follow-up question would be, suppose a post has no other problems that have to be fixed, should I suggest an edit only removing the Stack Snippet markup? Or would it be too minor to worth the time of three reviewers?
    – user12205
    Commented Sep 25, 2015 at 2:18
  • 5
    @ace: Then you still edit out the snippets.
    – Cerbrus
    Commented Sep 25, 2015 at 4:40
  • 9
    @ace: Definitely. Inappropriate Stack Snippets are evil and should be killed with fire.
    – PM 2Ring
    Commented Sep 25, 2015 at 8:23
  • 1
    @ace: No remotely too minor, no. Commented Sep 25, 2015 at 16:38
26

Whenever I see a stack snippet be used for plain code markup I edit it out. First I find the Run code snippet button annoying when it is not a stack snippet as there is nothing to run. Secondly, screen space is limited and

Enter image description here

Is wasting a lot of space for nothing.

I also went through the post and cleaned it up a little as it was missing some capitalization and they had a single space before punctuation.

7

Of course, this is a mistake, so should be corrected via an edit.

I've previously suggested wording to try to alleviate this pattern, though at time of writing it has only been used for a mock-up of a much better interface; the editor button icon tooltip is still a bit misleading.

You must log in to answer this question.

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