19

Questions in the html, css, javascript and jquery tags tend to profit immensely from the asker providing a ready-made example on jsfiddle.net or a similar "live preview" service.

The problem becomes instantly visible; the answerer can enter, test and share their modifications straight away; stuff can get cross-browser tested in a breeze.

However, many askers simply are not aware that this great service exists.

I would like to see a prominent link to JSFiddle (or whatever service SO chooses to endorse, I don't really care but JSFiddle is my favourite) somewhere where people see it, especially newbies.

Can this please be done somehow?

If so, where could this be placed? The most fitting spot would obviously be when people enter their tags, and one of the relevant tags is among them. If you ask me, the benefits provided by this service are so huge that even a have you considered providing a live example for your question on jsfiddle.net? (or whatever), popping up dynamically for those tags, would be justified.

(For those not active in these tags, JSFiddle is a web site that provides you with a basic web page environment, with the JavaScript framework of your choice pre-loaded and ready to work. It's kind of a virtual workbench to test-run code snippets in, and share them.)

3
  • 15
    Incidentally... I cringe whenever I see an answer that consists of nothing but a link to jsFiddle (where presumably the solution lives). It's a great tool, but SO isn't a snippet site: if you can't explain what you're doing and why - in both questions and answers - then the future usefulness of your post is greatly decreased.
    – Shog9
    Commented Jan 4, 2011 at 18:08
  • 2
    @Shog9 yes, but a working JSFiddle is always a fine addition. I think the voting system is going to take care of that concern: In my experience, pure JSFiddle links don't tend to get upvoted that much.
    – Pekka
    Commented Jan 4, 2011 at 20:12
  • 2
    a fine reason to not give them the appearance of having an official "blessing". And a working JSFiddle answer that duplicates the asker's code doesn't answer anything.
    – Shog9
    Commented Jan 4, 2011 at 20:24

3 Answers 3

15

I'm all in favour of encouraging the asker to post a jsFiddle/jsbin/whatever example in addition to posting at least some code in the question, but I'm absolutely against only posting a jsFiddle example.

If a question is at all unclear without the jsFiddle example, I think it's an unacceptable dependency. There are any number of ways the example could become unavailable (e.g. asker deletes it, jsFiddle changes its URL scheme, ceases to exist, gets bought and changes its name or has a big outage...)

2
  • 1
    Absolutely, but as with answers, the system is taking care of this already: Many people turn away from questions that contain only a JSFiddle link.
    – Pekka
    Commented Jan 4, 2011 at 20:15
  • +1 Im the same, don't follow the links unless I see code in the question. I look JSFiddle et al as a supporting role.
    – nickhar
    Commented Nov 9, 2012 at 23:06
5

I'm not sure that's a good idea. Unless the question is 'am I doing it right', providing too much information can sidetrack discussion from the problem at hand (-1, broken on ie5, not enough jQuery, don't use tables, that's very ugly, ...). Also, what happens when/if jsFiddle goes down?

7
  • 2
    Hmm,. In the HTML and CSS tags, there are often lengthy descriptions that are hard to compose, and hard to understand ("I have three divs distributed across a line 500 pixel wide...") having a workbench to show the issue is usually the best way to go. I agree, though, that there is a risk of some people copy+pasting their whole damn project in. But those people already do that in the question itself, without the possibility of a live preview. The latter point is easy: In that case, switch the recommendation to some other service.
    – Pekka
    Commented Oct 25, 2010 at 9:26
  • @radp example from a minute ago: stackoverflow.com/questions/4013372/…
    – Pekka
    Commented Oct 25, 2010 at 9:44
  • @Pekka: that's an excellent example where the asker could have pasted a half-dozen lines of code and did post a drawing, both of which would have provided a context for posterity in a way that linking to jsFiddle would not. Ultimately, the onus is on askers to provide enough information to get the answers they need - if they can't or won't, then they don't get answers.
    – Shog9
    Commented Jan 4, 2011 at 18:04
  • 2
    @Shog9 You misunderstand why I want this. A JSFiddle is not only to paste code - it is to quickly provide a workbench for the answerer to work in. HTML and CSS questions are often trial & error exercises, even for the most experienced among us. Also, most good HTML/CSS answers need to be tested in at least three browsers. It takes several minutes to get a test environment running that replicates the OP's scenario, even if they provide the full code. With a fiddle, you can start working straight away. The benefit is immeasurable, and leads to much better answers.
    – Pekka
    Commented Jan 4, 2011 at 22:03
  • 2
    @Pekka: how much effort is it, really, to flip open JSFiddle and paste in a bit of code? I'm inclined to look at this suggestion as fundamentally the same as the ones asking for TopCoder-style server-side execution of C++/C#/Java snippets... Except that setting up a test environment for those languages actually requires you to switch away from your browser for a bit. You're asking for something that's already dead easy (for a good question) to be made even easier, but at best it's unnecessary feature-creep. Re: cross-browser: have you seen DocType?
    – Shog9
    Commented Jan 4, 2011 at 23:01
  • @Shog9 fair points. But I am merely suggesting mentioning the existing service when a question is asked and linking to it, not implementing the service inside SO. That's a huge difference, and a JSFiddle prepared by the asker is more valuable than me copy & pasting stuff from the question, no matter how well put it is.
    – Pekka
    Commented Jan 4, 2011 at 23:08
  • 2
    @Pekka: you're correct, there is a huge difference - as I noted, it doesn't save you nearly as much time and effort as it would users of more verbose, compiled languages... I rather think you're hoping it would encourage users to include information that's flat-out missing right now (as with that example you posted, where the author didn't post any code at all) - while that's certainly possible, it wouldn't really improve the question on SO. I still can't shake the feeling that when using JSFiddle is anything beyond than a tiny annoyance it's an incomplete question to start with.
    – Shog9
    Commented Jan 4, 2011 at 23:31
1

Absolutely people should be encouraged to use jsfiddle. Whenever someone asks a "why does this not work" question, and does not provide a jsfiddle link, I immediately look at their rep, and it is almost always a beginner user (<300). It drives me up the wall when someone asks a question like

My canvas is not being drawn to...

ctx.fillRect(x, y, w, h);

I have no idea how the canvas is created, how ctx is initialized, what x, y, w, or h are. maybe they are executing the above in the head before the page is loaded, maybe it's in a separate file that's not being loaded. It might be in a .cpp file... Chances are, by starting to design a minimal example they find the answer anyways.

This applies to answers too. If they provide a minimal example, it's easier for one to understand. If they do not, and instead say something like:

Use the << 0 operator to truncate the coordinates to integers

Novice programmers might not understand that.

You must log in to answer this question.

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