# Should we adopt “Stack Snippets” (runnable code snippets in posts)?

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?

-
Please see this comment too: On the Meta Stack Overflow post – rolfl Aug 27 '14 at 17:32
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! – Haney Aug 27 '14 at 19:00
@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. – Mat's Mug Aug 28 '14 at 2:03
@Mat'sMug - thanks, and done. – rolfl Aug 28 '14 at 2:07
@Haney do votes count as feedback? – Mat's Mug Aug 29 '14 at 20:02
@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. – 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

-
Even with JavaScript there are library dependencies. Mine are quite extensive. – Donald.McLean Sep 2 '14 at 17:37

Yes.

# 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).

-
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? – Simon Forsberg Aug 27 '14 at 17:29
@SimonAndréForsberg trust the unicorns. – Mat's Mug Aug 27 '14 at 17:34
Have faith in me @SimonAndréForsberg - 60% of the time my code works 100% of the time! – Haney Aug 28 '14 at 20:16
That's better than 100% of your code working 60% of the time @Haney! – RubberDuck Aug 28 '14 at 20:26
@RubberDuck HAH! Never heard that one. – Haney Aug 28 '14 at 20:34
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. – Malachi Sep 2 '14 at 13:13
That's a really good point @Malachi. – 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

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

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.

-
Is this a vote against implementing the feature, or is it just a comment that it will help readers, askers, but not answerers? – rolfl Aug 28 '14 at 18:59
I'm working on some updates that might make it more useful by allowing you to hide/show the snippets by default – Haney Aug 28 '14 at 20:17
@rofl It's more of a comment that is too long to fit in the comment section ;) – konijn Aug 28 '14 at 20:45
@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. – 200_success Aug 28 '14 at 20:49
@200_success I appreciate that idea, but phase 1 will probably be hide/show all. I can always work it from there, iteratively. – Haney Aug 29 '14 at 20:35
@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... – Malachi Sep 2 '14 at 13:23
@konijn - just pinging you back to this question, Please try out the snippets here on meta... wow us with a whopper! – 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>

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