19
\$\begingroup\$

A new feature called Stack Snippets was introduced that allows users to embed runnable code snippets in their posts. According to the blog post:

If you feel that a particular site should have Stack Snippets, post a feature-request on that site’s meta – if there’s support from the community there, we’ll enable them.

Well, I think Stack Snippets would be pretty great here, for several reasons:

  • Other users can run and test submissions directly from their browser, without even having to click another link
  • Test cases can be embedded naturally into posts, to verify that the code works properly
  • We could hide very long ungolfed commentated snippets within collapsed Stack Snippet blocks, so that people who want to see how everything works could, while the answer wouldn't get too long

Finally, here's an example of Stack Snippets in action. (Note that you can make them non-collapsed by default, so you can still see the code.) Try it out here!

collapsed Stack Snippet

And when expanded:

expanded Stack Snippet

\$\endgroup\$
6
  • 4
    \$\begingroup\$ I like it, but it'd be even better if it supported GolfScript! ;-) \$\endgroup\$ Sep 16, 2014 at 21:23
  • 2
    \$\begingroup\$ @ChrisJester-Young Technically, that could be possible if Ruby was supported, and "[w]e don’t have any specific plans at this time to implement other languages, but it’s something we might consider in the future." So that's not too inconceivable of an idea! :) \$\endgroup\$
    – Doorknob
    Sep 16, 2014 at 21:25
  • 1
    \$\begingroup\$ I actually want to port the GS interpreter to JS. Then Ruby isn't necessary. (Double-quoted strings will eval JS expressions rather than Ruby ones, however.) \$\endgroup\$ Sep 16, 2014 at 21:27
  • 3
    \$\begingroup\$ As long as they don't implement more languages, this is going to encourage JS-only challenges, but generally I think it would be very useful here. \$\endgroup\$ Sep 17, 2014 at 7:28
  • 1
    \$\begingroup\$ I am in full favor of this. It would have helped a lot in this question. \$\endgroup\$ Sep 17, 2014 at 22:48
  • \$\begingroup\$ Now related: codegolf.stackexchange.com/questions/40073/… \$\endgroup\$ Oct 21, 2014 at 2:49

2 Answers 2

9
\$\begingroup\$

For a site that doesn't tend to go in much for language-specific puzzles, JavaScript is doing pretty well here. In light of that, I see no reason to not enable this - enjoy!

hello world!

\$\endgroup\$
18
\$\begingroup\$

Yes

I see a couple potential issues, but nothing that's a deal breaker.

Crazy-inefficient code

Some snippets posted here (especially for golf) have insane runtimes, memory needs, etc. At the least, we should encourage users to mention this if what they're posting will use an inordinant amount of time/resources. (they should probably do this anyway, but I see it as more important if running it is a single click away).

The same could be said about anything potentially malicious, although I see a lot less of that in general.

Voting for pretty/easy

Pretty pictures get you votes, I think we can all agree on that. One-click runnable code would probably also get you votes, if only because people can immediately see output and verify it's correct. That's not really a problem, except that it's limited by language. Should JS answers have an advantage because the output is so accessible? Is that advantage large enough to worry about? I don't know yet, but it's a possibility.

So like I said, nothing that I consider a deal breaker right now, just things to ponder. On the whole, I think it would be a good addition. Even more so if there were more languages available (but I'm not holding my breath for that).

\$\endgroup\$
1
  • \$\begingroup\$ Inefficiency can be solved by implementing a timeout, but that would depend on the answerer being bothered, I guess. \$\endgroup\$
    – Sp3000
    Oct 24, 2014 at 12:40

You must log in to answer this question.

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