36

I was recently having a problem with an asynchronous server written in C++. I extracted the relevant code from my project, stripped it down to what I believed was a minimal, complete, verifiable example (mcve), but all told it was still over 350 lines. I felt this was too big to post in a question, so I put the files on github and linked to that.

One user complained that I had not provided an mcve. I believe I had, only it was on github and not SO. My question to meta is whether it is OK to link to github, or should the source always be included as part of the question? The mcve help page does not explicitly prohibit hosting code outside of SO. Searches on meta did not reveal an answer either.

The problem was really with an inexplicable delay in the transaction, not the code itself. In order to properly log program state across the entire transaction, I needed to include a lot of server code, which in C++, was wordy. I could probably have made the example a bit rougher and trimmed another 100 lines, but would a 250 line example somehow be small enough?

9
  • 26
    The problem with having the relevant content off-site is that if the off-site location is unavailable for some reason (off-line, something gets moved, etc.), the question is not meaningful. (And to forestall objections about that not happening, I quite frequently run into invalid links to Microsoft content, and if it can happen there it can happen at Github.) Questions (and answers) should be self-sustaining, with off-site information only provided as additional resources. If it can't fit in your post here, it's still not a MCVE, and you need to further distill the problem down.
    – Ken White
    May 12, 2015 at 1:46
  • 1
    Thanks, @KenWhite. Yes, there is risk of loss of code if it is stored off-site. Some follow up questions: 1) How can I request that the help page be revised to make it clear that off-site code should be avoided? 2) Has the idea of SO itself hosting larger bodies of source code outside the question been floated? This would keep the questions more readable, though it could disincentivize people from creating minimal examples. 3) Your comment reads like a decent answer. Why isn't it one? ;) May 12, 2015 at 2:15
  • 1
    With regards to #3, @Makoto seems to have done it quite well. The What topics can I ask about here? page does mention that the code should be here in the question itself (see the numbered list on that page) I can't speak to SO hosting larger bodies of code, but that would seem to be self-defeating - "post a MCVE so that the question's more generally useful, but we'll post your big wall of text here for you".
    – Ken White
    May 12, 2015 at 2:27
  • Out of interest: what is the link to the question?
    – Gimby
    May 12, 2015 at 11:45
  • @Gimby stackoverflow.com/q/30179476/1927206 ? May 12, 2015 at 13:00
  • 5
    Based on the source SO question and the (very valuable) answer I can ask a followup question: if you have the need to post the code of basically your entire application platform to not provide evidence where the problem comes from but to maximize the chance that people reading the code can find the evidence for you - is it going to be a proper SO question? I don't think so. No offense intended, just the way I interpret the way the question is asked. Especially because it goes all over the place, blaming both the code (but no specific code) and the testing procedures.
    – Gimby
    May 12, 2015 at 14:51
  • 1
    Good point, @Gimby. I was not sure if the problem came from my implementation of an asynchronous server in cpp-netlib, or my use of curl in testing it, the interaction between the two, or something else. I did my best to phrase the question and prepare the example code in a way that would make it easy for others to spot the problem or try experiments I could not think of, but in doing so I perhaps deviated from the ideal SO question format. How would you recommend I phrase such a question in the future? May 12, 2015 at 21:47
  • I'm no Stackoverflow ninja, but in my opinion you answer that yourself in your own question. You shouldn't ask the question until you actually do have proof it is in a specific area of your problem domain. Case in point: in this situation it wasn't the code at all, but a fault in a library. It might also have been a problem in your network or operating system, or as you suspected yourself a fault in the method of testing.
    – Gimby
    May 13, 2015 at 8:55
  • 3
    One other note: A proper introduction before the code block can make the size of the MCVE a non-issue. Personally, I'd rather see a large MCVE with a good introduction than have a short MCVE be the first thing in the question.
    – skrrgwasme
    May 13, 2015 at 18:52

1 Answer 1

52

The idea isn't to have a small amount of code, it's to have the smallest amount possible that replicates your specific problem. If you've felt that you have narrowed it down, then that's fine. Nuanced problems may take up a bit more code.

(It's also a great thing if the code is copy-and-paste compilable; that is, if I open up my editor, paste it in there, save it and compile it, I shouldn't get any syntax errors. Ideally it should replicate the same problems you have.)

The main issue with linking to external sites is unpredictability. I'm reminded of the time that GitHub was under the largest DDoS attack it had ever seen, and this coincided with a team of developers attempting to hack together some code on a Sunday in March for a rather big national competition. The site that I had felt was rock solid and reliable had let me down. While I can respect that a DDoS is something few can truly prepare for, the fact of the matter remains: I had limited access to a service that I critically needed.

The same thought should be had when posting content here. If Stack Overflow gets hit with a denial of service attack, you're not going to be able to read either the question or answer. Conversely, if a site that you're hosting the bulk of your example goes down or is attacked, and Stack Overflow is up, you wouldn't have any context to go off of.

3
  • 35
    Also, sometimes people just delete their GitHub repos or accounts, leaving just a 404 page. May 12, 2015 at 2:29
  • 1
    That happened once in a much more unfortunate, corporate, production-related scenario that I recall, but yes, this is also a concern.
    – Makoto
    May 12, 2015 at 2:30
  • 5
    Let's not forget the offline dumps of SO that can be used in situations where access to Internet is not available or severely restricted (performance/firewall/...). Not all countries are blessed with highly available, high-speed Internet and not all companies have wide-open firewalls. May 13, 2015 at 9:56

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