27

I occasionally come across questions which contain HTML/CSS/JS which are formatted using the standard code blocks (backticks or indentation) that would be better as a runnable snippet. Is it good practice for me to edit these questions to make use of the snippet feature? I know the edit queues fill up quick so I wanted to verify that we should be making these kinds of edits before actually editing anything.

I did a quick search but couldn't find an answer for this, apologizes if it's been asked here before.

3
  • 8
    The only previous discussion I found that covers similar ground is this: meta.stackoverflow.com/questions/348648/… I don't have a particularly strong opinion, as most of my experience with Stack Snippets is negative (i.e., they've been erroneously added to questions not about HTML/CSS/JS, where they have no useful effect). If you're adding Stack Snippets to a post that make it a self-contained reproducible example, that seems like a useful edit. But, as always with edits, try to make the edit comprehensive, so also fix typos, etc.
    – Cody Gray Mod
    Commented Aug 24, 2022 at 19:29
  • 5
    @CodyGray funnily enough I made my first suggested edit today, which was to remove a snippet from some python code where it obviously made no sense (and to remove some noise) so I can see what you are saying. I frequent mostly web tags so I do see a decent amount of cases where they are used correctly and improve the quality of the question. I think I'll avoid suggesting adding them however unless there are other fixes I can make at the same time, as it's pretty easy to just copy the formatted code into something like jsfiddle. Commented Aug 24, 2022 at 19:58
  • 4
    Your plan seems like a good one. There are quite a large number of folks active in web tags that can (and will) unilaterally apply edits that change code to Stack Snippets (and that's it :( ). Thanks for asking, though; you're miles ahead of everyone who just blunders around this place, in my book. Commented Aug 24, 2022 at 20:09

2 Answers 2

23

I think I'll avoid suggesting adding them however unless there are other fixes I can make at the same time... Daniel Black

That's probably the safest thing to do. I would also add:

  • If it relies on an external library like jQuery, Bootstrap, Tailwind, etc., please also add it so the snippet works and looks like it should.

  • Only make it a runnable snippet if doing so actually demonstrates the problem described by the OP. If it's a situation where it's not possible to demonstrate the issue in the snippet at all (it's not missing code, it's a limitation/security issue for stack snippets) just leave it as a code block.

  • As someone who is suggesting edits, if someone added code that can't demonstrate the issue as is because they've got display: none all over the place, zero height sections, missing content, or other nonsense that makes the issue impossible to see (this actually happens a lot), I recommend just leaving it alone. You don't want to get your edit rejected for Conflicts with Author's Intent just for making the problem visible.

  • That said, adding image placeholders to replace broken images should be OK if you want to do so.

10

I find more often than not people use the stack snippets in the place of regular code snippets and the code doesn't run (usually from a JS import statement, but could be anything really). I always edit these to regular formatted code blocks. The issue with going the other way is that you often will need to add code or otherwise edit the existing code to get it into a running state, which IMO goes against the editing rules since it potentially changes the meaning of the code. It also has the potential to accidentally edit out the cause of any issues the author is asking about.

If the provided code snippet isn't sufficient enough to reproduce any issues the author describes it is best to ask them to edit their post and provide greater detail.

3
  • 4
    That's probably because you're more into the "react-js" area, for which StackSnippets aren't great to begin with. From my point of view, In the "vanilla" area, the majority of cases are ones where it's safe to convert to live snippets, because simply adding the obvious <div id="the-elem-being-targetted-in-the-code">some content</div> is all that's required to reproduce the issue. In such a case, converting to a live snippet is almost always an improvement.
    – Kaiido
    Commented Aug 26, 2022 at 5:25
  • 6
    I think the rule of thumb should be: If as an editor you're 100% confident you can make it a live snippet that does reproduce the issue, do so. Otherwise comment on the lack of details to reproduce the issue. Nothing more, nothing less.
    – Kaiido
    Commented Aug 26, 2022 at 5:26
  • @Kaiido That's a fair statement, React does have a few more moving parts to get working over vanilla JS.
    – Drew Reese
    Commented Aug 26, 2022 at 5:31

You must log in to answer this question.

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