32

One of our fellow SO members has been keenly proposing that SO snippets should trump external services like jsFiddle commenting answers in this question.

  1. Is there an overall consensus that snippets should be preferred over fiddles and alike?
  2. Are edits that consist of moving external code examples to snippets worth accepting (or indeed doing myself?) (believe I've found the answer to that here)

My view was that fiddles seem to be more flexible and have an ability to 'fiddle' with the code - in some cases thats more appropriate than the inbuilt snippet feature.

Guidance here is much appreciated.

15
  • 37
    Well we know that a stack-snippet will never become a dead link which is always possible with an external source.
    – Joe W
    Commented Aug 11, 2015 at 16:06
  • 4
    you can still "fiddle" with the code in a stack snippet, it just isn't as easy as jsfiddle.
    – Kevin B
    Commented Aug 11, 2015 at 16:07
  • why -1? is there UI to fiddle with the stack snippet or just the browser's inspector?
    – David
    Commented Aug 11, 2015 at 16:09
  • 4
    click copy snippet to answer, and begin editing it.
    – Kevin B
    Commented Aug 11, 2015 at 16:12
  • OK, this can't be marked as a duplicate since there isn't an answer there yet, but someone posted this question 10 minutes ago: meta.stackoverflow.com/questions/302278/…
    – BSMP
    Commented Aug 11, 2015 at 16:17
  • Lol it's the guy who was suggesting the edits to the answers - perhaps if both sides are unclear on what is correct or incorrect these questions should not be downvoted?
    – David
    Commented Aug 11, 2015 at 16:18
  • 1
    @BSMP On Meta, the question you're using as a dupe target does not require an answer.
    – Kendra
    Commented Aug 11, 2015 at 16:34
  • 1
    @BSMP I chose this question as it has an answer. Commented Aug 11, 2015 at 16:36
  • @DavidAnderton - I personally didn't vote on either of them. I don't have a guess now as to why both got a down vote.
    – BSMP
    Commented Aug 11, 2015 at 16:50
  • 1
    @canon Well I think it was to do with the edit to my answer from evolutionexbox, that I rejected as it was making my loose code a stack snippet whereas I had provided a fiddle. Tiny-Giant went ahead earlier today and edited it into a snippet: stackoverflow.com/posts/31946170/revisions despite this discussion here meta.stackoverflow.com/questions/271589/…
    – David
    Commented Aug 12, 2015 at 14:04
  • 5
    @Joe W: "we know that a stack-snippet will never become a dead link" mplungjan would beg to differ.
    – BoltClock Mod
    Commented Aug 12, 2015 at 15:17
  • @canon: That is true indeed.
    – BoltClock Mod
    Commented Aug 12, 2015 at 15:29
  • 1
    It'd be nice if stack snippets were accessible as a standalone site.
    – j08691
    Commented Aug 12, 2015 at 15:52
  • 1
    If the stack snippets were 1/10th as useful as a fiddle/bin/bench I'd be all for it, but they are not. Stack snips are not about providing quality answers, they are entirely intended to capture traffic and contribute to SEO. Commented May 5, 2017 at 18:40
  • What about codepen.io it's have autocomplete as advantage over jsfiddle
    – Alex78191
    Commented Jun 1, 2017 at 1:01

2 Answers 2

36

Where possible I usually try to include both a Stack-Snippet and a jsFiddle.

I still prefer working on people's problems in jsFiddle, not that jsFiddle is inherently better, I'm just used to the work flow there. I include a Stack-Snippet as well because I'm aware that jsFiddle goes down from time to time and having an in-answer working example is helpful.

Now that that's out of the way...

Feel free to ignore comments requesting the use of either tool, they're a nice addition to posts where applicable, but they're not required. As long as your answer contains -- you know, an answer -- you're fine.

9
  • 1
    Thanks for taking the time to respond. There didn't seem to be much guidance on this, and as a more seasoned SO member it's useful to have your direction on this.
    – David
    Commented Aug 11, 2015 at 16:28
  • 3
    @DavidAnderton In a third party edit situation I would probably approve the addition of a snippet provided that they didn't remove the fiddle. Not an official policy or anything, just what I would do.
    – apaul
    Commented Aug 11, 2015 at 16:32
  • 15
    @DavidAnderton When determining the usefulness of a post, I always ignore any link markup to external material. So, if your answer does not include a snippet but does include a jsFiddle, you won't be getting an upvote from me (and would probably get a downvote), but if you include both you would get just as much of an upvote from me as if you didn't include a fiddle.
    – user4639281
    Commented Aug 11, 2015 at 17:37
  • I do this as well. StackSnippets are great for embedding a demo in an answer, but not ideal for playing around with existing code. Plus, the editor in JSFiddle is a bit nicer. Both places have their advantages and disadvantages, so I just use both.
    – Ajedi32
    Commented Aug 12, 2015 at 13:24
  • @TinyGiant What about code + fiddle instead of snippet + fiddle? Often there is a bunch of boilerplate or css or something needed to make the demo work right and it takes too much space as a snippet. So I just post the relevant code and link to an external demo.
    – DanielST
    Commented Aug 12, 2015 at 13:51
  • @slicedtoad You can always use the hide fiddle option to hide the full demo. Then just copy the important bits into a visible code block. You can also put irrelevant code in one line and prepend a bunch of white-space to push it out of the visible area. That way the main important bits are there for everyone to see and the irrelevant boilerplate code is hidden.
    – user4639281
    Commented Aug 12, 2015 at 15:20
  • @Tiny Giant: "prepend a bunch of white-space to push it out of the visible area" That horizontal scrollbar though...
    – BoltClock Mod
    Commented Aug 12, 2015 at 15:21
  • @BoltClock Yeah, if people really want to scroll they can, but if they don't have any other reason to scroll I would assume that they wouldn't, of course if there is also a vertical overflow then it would be less useful. Probably not the best solution, and I liked idea about hideable code blocks, but it does work when it works.
    – user4639281
    Commented Aug 12, 2015 at 15:24
  • 2
    Also, I should say that if an answer has code and a fiddle link, I will still ignore the fiddle and judge it as if it just had the code block. The code block itself may be useful enough in combination with the explanation for me to upvote. If an answer isn't blatantly off-topic, misleading,wrong, missing an explanation or code (where applicable), then I won't downvote. @slicedtoad
    – user4639281
    Commented Aug 12, 2015 at 15:27
48

Always prefer hosting the content on SO.

Thus, prefer having your pictures on SE's imgur-account, thus ensuring they will stay available as long as the SE network exists, instead of using any other option which can get unavailable independently.

The same logic applies to stack snippets and jsfiddle or the like, with some extra-advantage:
Stack snippets are versioned together with the rest of your post, not separately.

If you want to also make the same example available as a jsfiddle or the like, feel free, some people prefer that. Though keeping both synchronized, respectively making sure they are actually the same, is quite an added burden.

9
  • 8
    Bleh. Hosting everything on SO is a good goal for avoiding broken links if any third party services ever go down, but Stack Snippets as currently implemented just aren't as good as JSFiddle for many use cases. JSFiddle lets me modify someone else's work to experiment; snippets don't. And if I'm writing an answer where I want to include just a few lines of code the answer the question in the answer but also provide a full working example with 100+ lines of supporting/setup code, I can't do that with snippets; I can either dump all the setup code right into the answer, or hide it completely.
    – Mark Amery
    Commented Aug 11, 2015 at 21:51
  • 10
    When writing answers where the answer requires 4 lines of code but the demo requires 100, JSFiddle lets me compromise by making a full working example available that the user can read and experiment with without needing to break the flow of my answer with a massive dump of demo code. Snippets simply do not provide that functionality, as far as I can tell. There's no reason we couldn't have linkable snippets that behaved like JSFiddle, but right now we don't. Until we do, I'm afraid I'll keep using them sparingly, and frequently preferring JSFiddle.
    – Mark Amery
    Commented Aug 11, 2015 at 21:54
  • 7
    1. Just select "copy to answer", and you can fiddle with it to your hearts content. 2. If there's lots of boilerplate you don't want to shove into everyones face, you have to show the crucial lines separately either way, whether the full example is in a stack snippet or off-site. 3. You could make a FR for an additional link/button, allowing you to open it expanded in a new window/tab. But stack snippets without a backing post are unlikely to ever happen. Commented Aug 11, 2015 at 23:10
  • 1
    Deduplicator cc @Mark Amery: 1) The user experience doing that is abysmal 2) agreed 3) That's why I've decided to stop comparing Stack Snippets with JSFiddle et al, and trying to twist Stack Snippets into something that it clearly wasn't made to do (or at least, isn't working as SE intended). They are two very different things that just happen to involve executable user-generated code.
    – BoltClock Mod
    Commented Aug 12, 2015 at 15:27
  • @Deduplicator I don't quite get what your point is with 2. Of course I do need to include the crucial lines in my answer; my point was that I don't want to include the boilerplate lines in my answer, (but do want to make them visible to somebody who chooses to inspect and tinker with my demo). JSFiddle lets me do this. Snippets require that I either hide away the demo code from the reader or inline it in the answer. I don't want to do either; if I were to, the inclusion of the demo would usually end up making my answer worse instead of better. Hence, JSFiddle.
    – Mark Amery
    Commented Aug 12, 2015 at 15:31
  • 1
    A good analogy seems to be to having links to related off-site resources. It's perfectly acceptable (and reasonable) to write an answer about Fooing Bars and then say "Here's a link to a blog post that covers this as well as other similar tasks like Quxing Bazes" without having to quote the whole post in your answer. Hiding away tangential content behind links is a good thing, that lets the user read the essentials rapidly and only explore more deeply if they want to. This answer is the demo code equivalent of requiring all referenced prose to be quoted in full instead of linked to.
    – Mark Amery
    Commented Aug 12, 2015 at 15:44
  • 2
    @Mark: So jsfiddle lets you mark some lines as important, hiding the rest unless you explicitly ask for them? Haven't found that option yet, where is it? And it might be a good idea to allow sections of the answer (with a descriptive caption) which will only expand upon explicit request in general, not only for the sources behind a stack snippet. That might make a good FR. Commented Aug 12, 2015 at 16:22
  • @Deduplicator: That feature request has been made (I think there's at least one other out there). Sadly, as far as I can tell, Stack Snippets are abandonware. They have major problems and omissions, lots of feature requests, and AFAIK nothing's been done on them in close to a year. Which I'm frankly quite cross with SE about, because as you said, content should be on-site. They should be great, not marginal. Commented Aug 14, 2015 at 8:21
  • @T.J.Crowder: That redundancy-reduction FR is quite a nice gimmick, though I'm not sure of it's viability. Anyway, I meant whole fold-out sections of the post, containing snippets, codeblocks, prose and whatever else. Commented Aug 14, 2015 at 13:48

You must log in to answer this question.

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