52

Since the introduction of Stack Snippets, I've noticed them showing up frequently with non-runnable code. (I spend most of my time on the tag, which is a server-side js variant. I imagine that folks see the same. Sure enough - it's mentioned in this question for as well.)

screenshot

I can see value in Stack Snippets for js variants, for the code tidy-up within the editor and "copy to answer" function. But the "Run" button is prominent & useless.

Is there a way that I can edit a question to leave the snippet in place, but disable the "Run" button?

10
  • 17
    Personally I find the 'snippet' feature a bit of a white elephant which serves little or no purpose. I follow the Android tag and anybody who programs for Android knows it's impossible to run anything without a full app context which involves multiple code files...snippets are useless. I rip out the snippet-related stuff on anything that has Android-specific code in it and wish it was disabled for any question with the Android tag on it. I suspect that should also apply in other scenarios.
    – Squonk
    Commented May 30, 2015 at 16:59
  • 12
    Even worse, it's reasonably commonly seen in newbie questions in python, bash, lisp etc.
    – tripleee
    Commented May 31, 2015 at 10:41
  • 1
    For the whole "other languages" can of worms, ideone.com already does it for a big ole pile o f'em. Start with a clone of that?
    – tripleee
    Commented May 31, 2015 at 10:43
  • 4
    @Squonk snippets don't even support Java, much less the Android framework. My guess is that new users are just hitting the wrong buttons while creating questions. Perhaps we just need to make it more difficult to accidentally create snippets. Commented Jun 1, 2015 at 18:39
  • I've seen em in java Commented Jun 2, 2015 at 0:11
  • 2
    I see it in c++ from time to time -.- Commented Jun 2, 2015 at 0:18
  • 4
    A newcomer who sees a button labeled "code snippet" won't necessarily anticipate what that button does. Would it help if it were labeled "Interactive Code Snippet" or some such? It would make it at least slightly apparent that it's a feature, not just a way to post code.
    – rutter
    Commented Jun 2, 2015 at 0:28
  • 1
    For everyone complaining about snippets being misused, here's a feature request for you: meta.stackoverflow.com/questions/292421/…
    – BoltClock
    Commented Jun 2, 2015 at 11:14
  • Thanks for commenting on this 6-year old Q, @Henke! Now that you've reactivated it, it will get more upvotes, and I'll finally be able to exchange my magical internet points for cryptocurrency! ;^) It was reasonably relevant the month that the snippets feature was first introduced, and less so over time... tech is like that. No need to blow a gasket.
    – Mogsdad
    Commented May 11, 2021 at 16:21
  • But the "Run" button is prominent & useless. I still completely disagree on that. Normally, the very purpose of having a Stack Snippet is to show a live demo of runnable code. If not, just put it in a normal code snippet! But I may want to have my code in a Stack Snippet even when I don't want the code to be run: I may want to include an appendix with code to be retrieved only if any of my links get broken, and therefore have a need for a hidden snippet. In such a case it would be nice to have the ability to also hide the Run button, even when the snippet is shown. Commented May 30, 2021 at 13:19

3 Answers 3

40

If it's not a stack snippet (HTML+CSS+JS), don't use the stack snippet feature.

Copying a bog-standard code-sample to the answer is easy enough, the copy-to-answer button is not valuable enough to balance blatant misuse of the feature.

10
  • 2
    To extrapolate that pov, just use jsfiddle if you've got (HTML+CSS+JS). The whole feature is not valuable enough when it only supports those languages, and not in server variations. Point is, many first timers are using the feature inappropriately, and it would be more effective to fix the code than fix the users.
    – Mogsdad
    Commented May 30, 2015 at 15:41
  • @Mogsdad: Well, what language and platform should SE work on first? How should it detect that you the snippet is not used for client-side web-development, and what it's used for instead? And are you sure that's sufficiently more important than all the rest they could work on instead? Commented May 30, 2015 at 16:18
  • No need to get snippety! (hehe) As proposed, detection not needed - if it's not able to run client-side, it won't pass the "run first" rule. Far simpler. Partial support for JS variants - heck, for the whole C-like gaggle - could improve user experience more than full run-in-browser support for the next language stack. I don't know - hence the discussion. WRT relative importance - that's not for me (or you, I assume) to judge, nor is it relevant to the discussion.
    – Mogsdad
    Commented May 30, 2015 at 16:34
  • Well, I'm still missing what non-runnable js-only runnable-snippets have over standard code-blocks... Commented May 30, 2015 at 16:36
  • For the most part, the code being posted in a question doesn't work in the first place - so the "run" button doesn't help there, either. But the separation of HTML/CSS/JS helps clarify, the ability to include additional code that supports but isn't central to the question helps, clicking "copy to answer" saves a few clicks...
    – Mogsdad
    Commented May 30, 2015 at 16:43
  • 3
    I think it's nice to have a replacement for jsFiddle and CodePen and others that were often linked too. It would be nice if Runnable Snippets could run other kinds of snippets too, but HTML+CSS+JavaScript is as easy as combining them and feeding them to an iframe, so I think the next step would be excessively harder to build. Personally I'm glad with this feature, and I think it's acceptable that it works only for, basically, client-side web questions. The normal [code] button is there for other pieces of code, which is by the way also misused by new users..
    – GolezTrol
    Commented May 31, 2015 at 7:08
  • I posted such suggestion in a bit milder form.
    – PM 77-1
    Commented Jun 1, 2015 at 18:41
  • HTML+CSS+JS You can add that 3 languages are not required, a snippet can only display HTML to show a tag. Or HTML+CSS when the question is about stylesheet. Or HTML+JS when the question is about jQuery.
    – A.L
    Commented Jun 2, 2015 at 11:09
  • Or any combination of whatever is necessary to reproduce the problem. I don't think every possibility needs to be mentioned.
    – BoltClock
    Commented Jun 2, 2015 at 11:10
  • that was nice advice, but we need some shortcut on the editor. Not stack snippet and have language options. Commented Oct 30, 2017 at 5:25
22

Easily done, but not documented. (Until now, that is!)

Turns out there's zero tolerance on the syntax of the begin comment, therefore you can disable snippet controls by making that comment line invalid. A whitespace violation is enough, but I'm proposing using runnable: false in the hopes that it turns into a feature that only removes the "run" button, leaving the still-useful "copy snippet to answer" button.

<!-- begin snippet: js hide: false runnable: false -->

Other 'typos' that can disable the snippet widget:

  • remove space after open or before close comment markers

    <!-- begin snippet: js hide: false-->
                                      ^
    
  • any extraneous character

    <!-- begin snippet: js hide: false x -->
                                       ^
    
2
  • 1
    I found this out a while back and it made my life so much easier
    – user4639281
    Commented May 31, 2015 at 6:55
  • I posted a bug report some time ago that also concerns the handling of snippet delimiters: meta.stackoverflow.com/questions/284254/…
    – BoltClock
    Commented Jun 2, 2015 at 11:12
8

I really like the runnable snippets

I think it's nice to have a replacement for jsFiddle and CodePen and others that were so often linked too. It would be nice if Runnable Snippets could run other kinds of snippets too, but HTML+CSS+JavaScript is as easy as combining them and feeding them to an iframe, so it was the obvious choice to start with.

It's going to be hard to build it for other languages

I think the next step would be excessively harder to build. You'd need a completely different UI to select from a multitude of languages, and you require a big server capacity and complex configuration to run all that stuff. Because once there is a Node.js tool, PHP users will want one too. And eventually you'll be running COBOL code somewhere.

But let's still keep the current one

Personally I'm glad with this feature, and I think it's acceptable that it works only for, basically, client-side web questions, and removing this feature because it is misused doesn't seem the right way to go. After all, new users make mistakes with the normal code snippet button too. That's what new users do, and often it's simple to fix. A small checkbox to mark it as 'Non runnable' could make life easier for those who edit the questions.

And add some features to normal code snippets

But maybe there can be some modification to the snippets inserted by the normal {code sample} button. They could have a 'copy snippet to answer' button as well, and maybe also a possibility to select a language in case the automatic detection failed.

Doing so gives no a richer experience for normal snippets, and an additional simulator for client-side web code, which may in the future be expanded with other languages as well.

2
  • 1
    Note that there's already a way to select a language for highlighting if auto-detection didn't work: <!-- language: lang-whatever --> on a line separated by double newlines before the codeblock. Commented Jun 1, 2015 at 18:33
  • 1
    Of course, but it would be nice if there was some GUI element that helps you with this, so you don't have to find out by trial and error.
    – GolezTrol
    Commented Jun 1, 2015 at 20:21

You must log in to answer this question.

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