35
\$\begingroup\$

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?

\$\endgroup\$
6
  • 2
    \$\begingroup\$ Please see this comment too: On the Meta Stack Overflow post \$\endgroup\$
    – rolfl
    Aug 27, 2014 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 StaffMod
    Aug 27, 2014 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\$ Aug 28, 2014 at 2:03
  • \$\begingroup\$ @Mat'sMug - thanks, and done. \$\endgroup\$
    – rolfl
    Aug 28, 2014 at 2:07
  • \$\begingroup\$ @Haney do votes count as feedback? \$\endgroup\$ Aug 29, 2014 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 StaffMod
    Aug 29, 2014 at 20:33

7 Answers 7

30
\$\begingroup\$

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

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Even with JavaScript there are library dependencies. Mine are quite extensive. \$\endgroup\$ Sep 2, 2014 at 17:37
29
\$\begingroup\$

Short answer:

Yes.

Long answer:

Hell yes.

\$\endgroup\$
0
22
\$\begingroup\$

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

\$\endgroup\$
21
\$\begingroup\$

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

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

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

\$\endgroup\$
7
  • \$\begingroup\$ Your comment has been posted to chat, and there are some folk warming up for the big event. \$\endgroup\$
    – rolfl
    Sep 5, 2014 at 20:44
  • 3
    \$\begingroup\$ @rolfl No pressure or anything... ;) \$\endgroup\$
    – Haney StaffMod
    Sep 5, 2014 at 20:45
  • 2
    \$\begingroup\$ Just don't break anything when you flip that switch. ;-) \$\endgroup\$
    – Jamal Mod
    Sep 5, 2014 at 20:46
  • \$\begingroup\$ @rolfl what chat room are you in? \$\endgroup\$
    – Haney StaffMod
    Sep 5, 2014 at 21:24
  • 1
    \$\begingroup\$ @Haney - always The 2nd Monitor \$\endgroup\$
    – rolfl
    Sep 5, 2014 at 21:25
  • \$\begingroup\$ @Haney seen this? \$\endgroup\$ Sep 7, 2014 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, 2014 at 12:04
7
\$\begingroup\$

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.

\$\endgroup\$
7
  • \$\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, 2014 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 StaffMod
    Aug 28, 2014 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, 2014 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\$ Aug 28, 2014 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 StaffMod
    Aug 29, 2014 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 Mod
    Sep 2, 2014 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, 2014 at 21:55
4
\$\begingroup\$

Snippets are alive!

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

\$\endgroup\$
3
  • \$\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\$ Sep 5, 2014 at 21:31
  • 1
    \$\begingroup\$ In fact, you can step directly from 1 to 4. \$\endgroup\$ Sep 5, 2014 at 21:31
  • 1
    \$\begingroup\$ I didn't see the close way over there on the right. \$\endgroup\$
    – Malachi Mod
    Sep 5, 2014 at 21:44

You must log in to answer this question.

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