36

Background

Questions that revolve around asynchronicity are very common and are asked on a daily basis on Stack Overflow. To back up this claim, How to return the response from an AJAX call? is the #1 question under the JavaScript tag's "frequent" tab.

This kind of question is asked so often that it can almost be considered a form of spamming (from my personal view). I'm aware these are mostly legit questions, because every starter has issues with understanding asynchronous logic flow at some point.

But even then, trying to teach this basic concept to every single JavaScript starter takes an overwhelming effort from the community. Seeing as there is little to no benefit in answering such questions which have already been answered thousands of times, the effort simply does not pay off as it would just duplicate the data from another thousand of answers.

Most of the time, those questions tend to be closed as a duplicate of the aforementioned question, which explains asynchronicity very well in the answers.

However, that "generic" question is tightly related to Ajax, hence I'm not sure if it could be considered a valid canonical reference for all asynchronicity-related questions.

In practice

Today I've come across this question, which I've pondered whether to close for a good while. I was considering to cast a close vote as a dupe of the aforementioned question, and let the community decide whether it is a dupe (whether it gets another 4 close votes or not).

However, due to the new system changes, as I hold a gold JavaScript badge, a single close-vote from me would automatically close the question and, viewing from a neutral point of view, closing that question as a dupe of "returning the response from an Ajax call" would seem like a mistake at first glance, as the question at hand has nothing to do with Ajax nor returning values.

So instead of closing it as a dupe of a seemingly-unrelated question, I've decided to try to re-iterate the asynchronous explanation one more time. But apparently, the questioner in this case doesn't even have a clue about asynchronicity. Not only I'm wasting effort into making yet another answer to this generic question, but it is also nearly to no use to someone who has no grasp of the asynchronous world, such as OP in this case.

So, is there a canonical reference question for JavaScript asynchronicity that we can mark such questions as a duplicate of? Or should one be created?

In short

JavaScript answerers should not waste time and effort into this kind of question which has been asked and answered thousands of times, instead, we should redirect the questioners to a canonical topic which contains more info than any of the scattered duplicates could gather.

Is there such a canonical question? Would the aforementioned topic be considered "canonical enough"? If the answer is "no" to both of these questions, should a canonical topic be created? Or is there any other possible solution to get rid of these spam-esque questions?

32
  • What would the title of the canonical question be? Could it be definitively and comprehensively answered in substantially less than 30,000 characters (the system limit on answer size)?
    – Robert Harvey Mod
    Commented May 14, 2014 at 20:00
  • @RobertHarvey Good question, I was thinking about the title midway through writing this topic but still haven't got a good one. 30k chars is (imho) quite generous, as very few would read that amount of characters. I would suggest making it a community thread as well, with possibly more than one answer. Commented May 14, 2014 at 20:04
  • 4
    Perhaps the JavaScript community wants to consider these questions as simply "too broad", as the amount of explanation required for the questions to be answered is beyond a reasonably scoped answer.
    – Servy
    Commented May 14, 2014 at 20:05
  • I am concerned that the examples you are providing appear to be highly-specific troubleshooting questions. Unless the problem is specifically "How to return the response from an Ajax call," I'm not sure that you can reasonably call it a dupe.
    – Robert Harvey Mod
    Commented May 14, 2014 at 20:06
  • @Servy well, one can post a working code with barely no explanation and that's rather acceptable. Problem is, OP will not understand the root of the problem and will repeat the issue and make more and more questions about asynchronous logic. Commented May 14, 2014 at 20:06
  • 1
    Is that a reality, or just supposition?
    – Robert Harvey Mod
    Commented May 14, 2014 at 20:07
  • 5
    @RobertHarvey I supposed you could possibly create a, "How can I return the response from this asynchronous method call?" in which the question defines a new (and trivially basic) asynchronous method, and that would have an answer very similar to the referenced question. It might be possible for a somewhat long, but still SO-scoped, answer.
    – Servy
    Commented May 14, 2014 at 20:08
  • I'm inclined to agree with @Servy on this one. Posting working code for someone who doesn't understand the concepts is not a good answer. A good answer would be too long, because you have to teach them the basics before they will understand your code. It is the very definition of too broad, although arrive at in a roundabout way.
    – Robert Harvey Mod
    Commented May 14, 2014 at 20:08
  • 2
    @RobertHarvey well, from experience, I've seen the "return response from ajax call" being used to close questions that are just about asynchronicity quite a few times. That is because most people just can't be arsed to repeat themselves over and over again. That is in the top 3 most asked topics under JS tag for sure. Commented May 14, 2014 at 20:08
  • @RobertHarvey If only people didn't abuse "minimal understanding"...because that's exactly the situation here...I suppose a custom close reason with a similar sounding text is one option.
    – Servy
    Commented May 14, 2014 at 20:08
  • Yeah, I could see that question with 2 or 3 close votes for "no minimal understanding" right now if that close reason still existed. Commented May 14, 2014 at 20:10
  • @FabrícioMatté It's still a valid reason to close a question, as per the help center, and this is exactly the situation it was designed to solve, it's just that the vast majority of times people actually used it was for "you didn't try hard enough" and not, "you wouldn't understand the answer, even if we gave it to you".
    – Servy
    Commented May 14, 2014 at 20:11
  • 1
    Still, it would be nice to have a proper canonical question (similarly to how PHP has "reference questions"). Commented May 14, 2014 at 20:16
  • 1
    @FabrícioMatté Then try and make one. If it doesn't work out, and people don't see value in it, then you can always delete it.
    – Servy
    Commented May 14, 2014 at 20:17
  • 1
    @RobertHarvey By the way, I agree that not providing enough explanation is a bad answer, however most OPs will be happy with working code and throw the green checkmark in the answer, then come back the next day with the same issue. Commented May 14, 2014 at 20:23

2 Answers 2

18

Here's my attempt at creating a canonical question: Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference

Most likely there are improvements to be made, hence I've marked the answer as Community Wiki. Everyone is invited to edit and improve it (fix grammar, add resources or better explanations), and of course, feel free to submit a completely new answer of your own if you'd like.

I hope the efforts into that thread can serve as a canonical topic for JavaScript asynchronicity questions which do not involve Ajax.

7
  • 6
    Thanks for taking the time to do this! I was wondering myself recently what would be the best approach to write a generic canonical question about async stuff, but I couldn't find the time to do it. I haven't read it yet, but I will once I'm home. Commented May 15, 2014 at 0:25
  • @FelixKling Thank you! I'll be sleeping soon, but please feel free to fix or make suggestions or submit your own answer (if you find the time) as well! Thanks. :D Commented May 15, 2014 at 0:27
  • When I started learning JavaScript with SO, I would have answered dozens of these questions, each with slight difference. But these days this question is boring. Bookmarking the answer and next time I see this question, my Gold hammer will close it. Good Effort, adding it to my profile. Commented May 15, 2014 at 4:17
  • Nice one! And although we still don't have so many such questions about that on SOpt, this would be a nice content to have there too. What do you think? And just in case you're wondering whether it's appropriate or not to cross-post it on SOpt, see what our mod/CM said about it: chat.stackexchange.com/transcript/message/15626365#15626365
    – bfavaretto
    Commented May 20, 2014 at 19:07
  • @bfavaretto I've already read the cross-posting guidelines on SOpt, but woah! I didn't expect it to get your and Gabe's attention. =] Answering your question: Yes! I'm always in favor of making content accessible to as many people as possible. Though, I'm a bit busy this week -- got a lot of work to get done in the next 10 days and I wouldn't like to make a rushed translation. Perhaps we can give the topic one or two weeks to mature a bit more before cross-posting? I don't have any issues if you'd prefer to start translating it right away though. Commented May 20, 2014 at 19:44
  • Sure Fabrício, no rush, take your time! I'd prefer if you post it yourself, as that could grant you some well-deserved extra rep on SOpt :) In any case I can help translating, ping me in chat if you need to.
    – bfavaretto
    Commented May 20, 2014 at 19:51
  • @bfavaretto alright, will do. =] Commented May 20, 2014 at 19:53
5

(this is a comment on Fabricio Matté's answer, but it didn't fit in the comment box)

Your answer and references answers are very long and technical (thus susceptible to TL;DR). I think that someone who does not grasp the concept of asynchronicity will still not understand it after reading that answer.

To learn new concepts, analogies with the real world seem to work very well. Once, I encountered a question about this frequently asked problem, and despite having referred to many other sources and explanations (in the comments), the OP did not understand the solution. After posting an answer with an analogy, the concept suddenly got clear to the OP (and many others, judged by the number of votes and views).

So, I suggest to include a very short and simple analogy at the top of the canonical answer, to cater for those frustrated ones with a short attention attention span.

13
  • Beware of: All abstractions are leaky. And: All analogies are wrong. Commented May 15, 2014 at 17:15
  • Interesting, thanks for your suggestion. I believe my way of explaining helps visualizing what is what in a good enough manner for most people, but you're right about analogies helping a good amount of people. I'm not very good with analogies, but the "forewords" section's first link (Felix Kling's answer) contains a good analogy which I've recommended reading. Please feel free to edit in a better analogy or make a complimentary answer with an analogy. =] Commented May 15, 2014 at 17:43
  • And yes, as @Deduplicator commented, I tend to avoid analogies because none is 100% accurate and (added with my lack of analogy-writing ability) tend to create a false expectation/minor misunderstandings about the topic when I try to use them. But if you can do better, feel free to. ;) Commented May 15, 2014 at 17:48
  • 2
    100% accuracy is not needed for an introduction to a concept *. With a good anology, one can get an intuitive understanding of the concept. Thereafter, it becomes easier to learn more about the details. It's like poking in the dark versus stabbing at an object in a dim light. * in this case, making up analogies is easy, but finding an analogy of a few lines that does not compromise too much on accuracy is a bit more challenging.
    – Rob W
    Commented May 15, 2014 at 19:29
  • Agreed. I can't think of a good analogy for that at the moment though, so I don't have a choice but to leave it up to the community, unless a miraculous happen and I manage to come up with one. Commented May 16, 2014 at 0:26
  • I've added a separate answer which focusses on analogy throughout... again; it's CW, so feel free to edit as necessary! (cc @FabrícioMatté).
    – Matt
    Commented May 29, 2014 at 9:15
  • @Matt I have edited that answer and inserted a comment. There's one part of the answer that is incorrect. Could you fix that part and remove the inline comment?
    – Rob W
    Commented May 29, 2014 at 9:33
  • @Rob: I was under the impression that onload would fire immediately if the image was cached. I've tested it myself (jsfiddle.net/68BNP) and can't reproduce... the good news is that if I'm wrong, then it shortens the analogy a bit :P
    – Matt
    Commented May 29, 2014 at 9:49
  • @RobW: I've updated the post. Does that comment surrounding the "alert" read any better now?
    – Matt
    Commented May 29, 2014 at 9:57
  • @Matt That comment makes more sense right now. Though personally I find that there is still room for improvements. Most beginners overlook that JavaScript does not wait until the response is ready. Your answer characterised this as "the JavaScript engine goes off and does something else.", which is vague. There is only one line that hints that the execution of JS does not block. (if the user knows a bit from other languages (e.g. Java, C++, shell scripting), then they would probably ask "Why can't I just put a Sleep over there" or something like that.)
    – Rob W
    Commented May 29, 2014 at 10:36
  • @RobW: I'll happily admit the section you're finding holes in was the section I was struggling most to write... I'm open to any suggestions. I've another look in a few hours time, otherwise I'll start dreaming about asynchronous code!
    – Matt
    Commented May 29, 2014 at 12:01
  • @Matt thanks for the effort! I'm without time to read and throughout analyze it at the moment, but I should be able to check back in the next 24 hours. At a first glance, your analogy with the code is excellent, but maybe the "shouldn't be here" part could do with a bit more of explanation (e.g. "not done yet"). Commented May 29, 2014 at 13:26
  • Oh never mind my observation above, I've just noticed that the code comment which I referred to is explained below the code. Commented May 30, 2014 at 1:05

You must log in to answer this question.

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