102

I find it extremely cumbersome that code snippets add lots of buttons and borders and make it much harder to read through questions.

I answer a lot of question in , and in a lot of questions snippets are used to format the source while about 1 of 500 snippets is actually runnable code and then it's usually just plain html without any code.

When code snippets are used for code that is not actually runnable, they add a lot of clutter that doesn't add any value. At first glance the page consists mostly of buttons and borders and I have to refocus to actually be able to see the relevant parts of the question.

  • make it more obvious that snippets should only be used for runnable code or prevent reuse in some other way
  • add another button that allows to remove snippets with one click when they are inappropriate.

A few examples from the last 3h

update

Found also

22
  • 58
    While we are at it can remove them from languages they do not belong on, or at least hide them? I hate having to edit out code snippets in C++. Sep 16, 2016 at 11:47
  • 1
    Angular2 uses TypeScript and it's possible to make it run in sippets but usually people don't bother to set it up properly. I also hate it. Sep 16, 2016 at 11:48
  • 3
    Related or even duplicate : meta.stackoverflow.com/questions/274636/…
    – Walfrat
    Sep 16, 2016 at 11:57
  • 18
    Snippets as whole were a poor, half-baked feature. Their design fails to address the use cases that JSFiddle was great for; meanwhile, their abuse by those who don't understand the editor's UI has lumbered us with a bunch of broken posts and extra cleanup work. They have done harm on net, and the site would be better without them.
    – Mark Amery
    Sep 16, 2016 at 12:59
  • 4
    I guess they are nice on tags that are about pure JS and jQuery but besides that, I also doubt they provide much value. Sep 16, 2016 at 13:02
  • 2
    Sometimes I post a comment like "I can't run that JavaScript" when the code is actually Java but with wrong snippet language. And funnily/annoyingly, a user once rejected my edit when I removed that wrong snippet language.
    – Sufian
    Sep 16, 2016 at 13:05
  • 3
    @GünterZöchbauer even there they suck for 99% of questions. Typically with UI code (which is all that snippets can reasonably be used for) there is a small amount of code (perhaps a single line) that actually answers the question, but a dozen or dozens of lines needed (including HTML, JS, and CSS) to set up a demo that the answer works. The ideal solution is thus to put the answer in the, well, answer, and to then stick a demo behind a link, where it can be opened and studied in full on its own page. JSFiddle lets me do this; Stack Snippets demand I either hide the demo code or inline it.
    – Mark Amery
    Sep 16, 2016 at 13:07
  • 5
    @MarkAmery: I find that that is a awfully pessimistic view of the functionality of stack snippets. There are plenty of answers where a function can easily be demo'd using a snippet.
    – Cerbrus
    Sep 16, 2016 at 13:13
  • 4
    @Cerbrus whoa, stack snippets have a console now?! Didn't know that - I see it was announced on MSE instead of MSO, so not surprised I never saw it. Wow, that actually adds some utility.
    – Mark Amery
    Sep 16, 2016 at 13:25
  • 13
    JSFiddle just hides the code in another site. I hate it when I see someone answer with "Try this: [fiddle]" and yes, I flag those as link-only, but using JSFiddle for SO questions/answers encourages that kind of laziness. I've also had many people argue with me when I ask them to include code in the question itself ("It's right there, in the fiddle/codepen/plunkr."). Woe betide the answerer whose company blocks code sharing sites. Don't get me wrong: I use jsfiddle a lot to try out ideas, but it's not that hard to copy and paste to a snippet. Let's not throw the baby out with the bathwater. Sep 16, 2016 at 13:41
  • 4
    I've also had many people argue with me when I ask them to include code in the question itself @MikeMcCaughan - Especially when some other user(s) already told them to do a fiddle/codepen/plunkr instead in the comments.
    – BSMP
    Sep 16, 2016 at 13:52
  • 2
    @MikeMcCaughan Hiding (irrelevant) code is the point. When I read an answer, I want to see the code that actually answers the question asked, without having to wade through library inclusions and a bunch of styling that's purely to make the demo prettier. Users dumping dozens or hundreds of lines of code in questions where the problem could've been demonstrated in 5 or less remains a far more frequent problem than code being hosted off-site (and a more difficult one for editors to fix), and snippets encourage that bad behaviour.
    – Mark Amery
    Sep 16, 2016 at 14:15
  • 1
    This problem exists throughout all tags, and I suggest a drastic amount of nuclear warning signs between the user and any text box.
    – Siguza
    Sep 16, 2016 at 20:04
  • 3
    Just some stream of consciousness ... I find Stack Snippets serving answers better than questions (Answerers usually know, how to use them correctly.) A first aid to the problematic usage in all questions would be to allow Stack Snippets on questions tagged with "snippet-eligible" tags only. If implementing tag-dependent snippets is not possible (it's hard, I know, the free order of the question creation, later tag edits etc.), I'd consider to remove the tool from the question editor altogether. This maybe sounds harsh, but the ratio of 1:500 is not much over-estimated.
    – Teemu
    Sep 16, 2016 at 20:05
  • 5
    Personally, I contribute mostly under the jQuery tag and have always found snippets useful in both questions and answers and would hate to see them removed there. That said, I can see a change may be needed for other languages. Sep 16, 2016 at 21:49

1 Answer 1

2

I appreciate being able to actually see someone's MCVE without leaving the question (yes, even when it's just a CSS question) but I realize I'm in the minority opinion on this, at least on Meta. That said, I've also seen people using them for the incorrect language.

add another button that allows to remove snippets with one click when they are inappropriate.

I think I have a solution for this in the meantime. From what I can tell, there's a quick, manual way to flatten a Stack Snippet. You want to just edit out these lines in the Markdown:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- end snippet​ -->

The code just turns into a set of code samples at that point for the languages used.

Again, this is a solution in the meantime, not an argument against the feature request.

4
  • That's what I do. I open the edit view, use the browser search feature to search for snippet and then delete these lines. But that's very cumbersome and error-prone and it takes often several seconds when saving edits. I also removed them once on a answer where it actually was runnable code because I just always remove them when I see them, because in the tags I monitor they are just always invalid (except this one case :D ) Sep 16, 2016 at 13:41
  • 4
    “I appreciate being able to actually see someone's MCVE without leaving the question” – This assumes that the person creating the snippet actually knows what they are doing and sets it up properly. Which is unfortunately very rare.
    – poke
    Sep 17, 2016 at 8:53
  • 2
    @poke - I didn't think it was necessary to point out that I was referring to properly set up snippets but I can edit that in there if it will help.
    – BSMP
    Sep 18, 2016 at 0:35
  • 1
    I am making and converting snippets all day long. I enjoy helping Askers and Answerers alike. I do not make snippets containing angular, because I do not do angular, but for the rest I try.
    – mplungjan
    Nov 27, 2017 at 6:48

You must log in to answer this question.

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