Stack Overflow is implementing a new feature whereby the question (and answers) can contain runnable code snippets:

Feedback requested: Runnable code snippets in questions and answers

Today we're proposing a new feature to the Meta Stack Overflow community: Stack Snippets.

What do Stack Snippets do?

Stack Snippets make code blocks runnable.

What's supported?

Stack Snippets work for both questions and answers. The currently supported languages are:

  • HTML
  • CSS
  • JavaScript

The intention appears to be that in future other languages will be supported as well.

Would Code Review benefit from this feature? Should we request to have it included here too?

  • 2
    \$\begingroup\$ Please see this comment too: On the Meta Stack Overflow post \$\endgroup\$ – rolfl Aug 27 '14 at 17:32
  • 10
    \$\begingroup\$ Just a heads up that I see this post and am monitoring it. If the community shows interest, I don't see why we wouldn't give them what they want. Solicit more feedback! \$\endgroup\$ – Haney Aug 27 '14 at 19:00
  • 2
    \$\begingroup\$ @rolfl would featuring this post help solicit more feedback? I don't lurk in html/css/js much, but I can see a very nice addition to the site with this, a bit like MathJax has been. \$\endgroup\$ – Mathieu Guindon Aug 28 '14 at 2:03
  • \$\begingroup\$ @Mat'sMug - thanks, and done. \$\endgroup\$ – rolfl Aug 28 '14 at 2:07
  • \$\begingroup\$ @Haney do votes count as feedback? \$\endgroup\$ – Mathieu Guindon Aug 29 '14 at 20:02
  • 3
    \$\begingroup\$ @Mat'sMug in part. It's not some hard and fast arbitrary secret formula or rule I'm hiding. I just don't want to advocate turning it on if only 5 of you want it. If it seems nobody has anything really bad to say about it, and a bunch of you are for it, then we'll probably flip the switch here once released. \$\endgroup\$ – Haney Aug 29 '14 at 20:33

Yes, but...

One important thing to remember if/when we do get this running is that:

  • Just because it doesn't run in the SE Code Snippet doesn't mean that it's broken code.

We often do reviews were the code is working but not directly compilable/runnable, because some classes are omitted / outside the scope of review.

Related: Encouraging users to include a code-snippet that proves that their code works

  • 2
    \$\begingroup\$ Even with JavaScript there are library dependencies. Mine are quite extensive. \$\endgroup\$ – Donald.McLean Sep 2 '14 at 17:37

Short answer:


Long answer:

Hell yes.


Yes, Code Review would benefit. I'm surprised that Stack Exchange didn't roll out this experimental feature on a beta site first. We already have questions and answers that make use of third-party services such as JSFiddle and JSBin that basically do the same thing (though perhaps those third-party sites are currently more featureful).


Okay, yes. It seems that we like this, but no one has really mentioned why it benefits CR so much.

All right smart guy, wanna tell us why?

Sure. It's because, unlike many other programming related SEs, we require the code in our question to work. There's often confusion over whether or not code is functioning code. This could hugely simplify determining that (at least for the JavaScript, CSS, and HTML).

  • 4
    \$\begingroup\$ However, what if there's a bug in the SE code-thingy so that the code doesn't work here but will work on other sites? \$\endgroup\$ – Simon Forsberg Aug 27 '14 at 17:29
  • 9
    \$\begingroup\$ @SimonAndréForsberg trust the unicorns. \$\endgroup\$ – Mathieu Guindon Aug 27 '14 at 17:34
  • 4
    \$\begingroup\$ Have faith in me @SimonAndréForsberg - 60% of the time my code works 100% of the time! \$\endgroup\$ – Haney Aug 28 '14 at 20:16
  • 3
    \$\begingroup\$ That's better than 100% of your code working 60% of the time @Haney! \$\endgroup\$ – RubberDuck Aug 28 '14 at 20:26
  • \$\begingroup\$ @RubberDuck HAH! Never heard that one. \$\endgroup\$ – Haney Aug 28 '14 at 20:34
  • 3
    \$\begingroup\$ The only problem with Javascript, HTML, and CSS is that it depends on the browser, so the code is going to act differently depending on the browser that the person is using. \$\endgroup\$ – Malachi Sep 2 '14 at 13:13
  • \$\begingroup\$ That's a really good point @Malachi. \$\endgroup\$ – RubberDuck Sep 2 '14 at 13:14

Just a heads up that I'm releasing a new version of Stack Snippets in a few minutes and I'll flip the switch on Code Review Meta at that time as well for you all to experiment with it.

The feedback on this post has been almost entirely positive (with some suggested improvements to Stack Snippets of course) so it makes sense to enable it for you all. Once it goes live, I'll update this answer again. Please experiment with it and provide feedback!

EDIT: Snippets are now live on Meta Code Review

  • \$\begingroup\$ Your comment has been posted to chat, and there are some folk warming up for the big event. \$\endgroup\$ – rolfl Sep 5 '14 at 20:44
  • 3
    \$\begingroup\$ @rolfl No pressure or anything... ;) \$\endgroup\$ – Haney Sep 5 '14 at 20:45
  • 2
    \$\begingroup\$ Just don't break anything when you flip that switch. ;-) \$\endgroup\$ – Jamal Sep 5 '14 at 20:46
  • \$\begingroup\$ @rolfl what chat room are you in? \$\endgroup\$ – Haney Sep 5 '14 at 21:24
  • 1
    \$\begingroup\$ @Haney - always The 2nd Monitor \$\endgroup\$ – rolfl Sep 5 '14 at 21:25
  • \$\begingroup\$ @Haney seen this? \$\endgroup\$ – Mathieu Guindon Sep 7 '14 at 20:03
  • 1
    \$\begingroup\$ @Haney - putting together a gallery of actual real use-cases of Stack Snippets on Code Review main site. \$\endgroup\$ – rolfl Sep 11 '14 at 12:04

Most of you know I have the gold badge in JavaScript, and I feel a bit ambiguous about this snippet feature.

It sure is cool to have something work within SO without going elsewhere. But.. the feature set seems to be too limited to actually productively write counter proposals at the end of a review. It seems a bonus for the asker, the reader, but not necessarily for the answerer.

@Haney, the things I like about jsbin/jsfiddle are

  • 1 click clone
  • Built-in JsHint
  • Built-in Beautify
  • Built-in support for Bootstrap/jQuery/Angular, you name it
  • Version/Milestone tracking
  • Autosave / autorun
  • Color syntax on HTML and CSS and JavaScript

Come to think, I would much ( much) rather have the Codereview bookmarklet integrated into SO: http://codereviewcommunity.github.io/CodeReviewBookmarklet/, that would be a timesaver.

  • \$\begingroup\$ Is this a vote against implementing the feature, or is it just a comment that it will help readers, askers, but not answerers? \$\endgroup\$ – rolfl Aug 28 '14 at 18:59
  • \$\begingroup\$ I'm working on some updates that might make it more useful by allowing you to hide/show the snippets by default \$\endgroup\$ – Haney Aug 28 '14 at 20:17
  • 2
    \$\begingroup\$ @rofl It's more of a comment that is too long to fit in the comment section ;) \$\endgroup\$ – konijn Aug 28 '14 at 20:45
  • \$\begingroup\$ @Haney If there is an option to hide/show snippets by default, then I think it should be for the HTML, CSS, and JavaScript sections individually, rather than all three at once. \$\endgroup\$ – 200_success Aug 28 '14 at 20:49
  • \$\begingroup\$ @200_success I appreciate that idea, but phase 1 will probably be hide/show all. I can always work it from there, iteratively. \$\endgroup\$ – Haney Aug 29 '14 at 20:35
  • 1
    \$\begingroup\$ @Haney hiding the code snippet doesn't make much sense for this answer. I think what konijn is saying is that he likes all the extras that come with jsfiddle or the other code sites and this fun tool is lacking most of those things. I assume if the StackExchange uses all those libraries that they are accessible to the Stack Snippets because they would be included on the site itself... \$\endgroup\$ – Malachi Sep 2 '14 at 13:23
  • \$\begingroup\$ @konijn - just pinging you back to this question, Please try out the snippets here on meta... wow us with a whopper! \$\endgroup\$ – rolfl Sep 5 '14 at 21:55

Snippets are alive!

.toclick {
  font-weight: bold;
<div class="toclick" onClick="alert('Why did you do that?')">click me!</div>

  • \$\begingroup\$ 1. click run code snippet. 2. click fullscreen. 3. click the back button. 4. ask yourself the question: Why is there a back button? \$\endgroup\$ – Simon Forsberg Sep 5 '14 at 21:31
  • 1
    \$\begingroup\$ In fact, you can step directly from 1 to 4. \$\endgroup\$ – Simon Forsberg Sep 5 '14 at 21:31
  • 1
    \$\begingroup\$ I didn't see the close way over there on the right. \$\endgroup\$ – Malachi Sep 5 '14 at 21:44

You must log in to answer this question.

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