# Editing in missing #includes

The off-topic list at meta includes:

• Questions containing broken code or asking for advice about code not yet written are off-topic, as the code is not ready for review.

So questions must compile and work, in order to be considered on-topic questions. Consider: Count every word occurrence from file. This code obviously will not compile as presented. It is missing four #includes (<string>, <iostream>, <vector>, and <fstream>). Based on the phrasing of OP's question, the code does work and the concern is simply algorithmic. So I simply editted in the includes.

This was removed due to:

Code in a question must never be edited. Your edit is more appropriate as a comment.

Obvious, but still an educated guess. We don't know the order of the includes, nor do we know if the code compiles despite missing includes. Therefore, putting the missing includes in there seamlessly is not appropriate; a comment would be better.

I find that reasoning ludicrous. The order of the includes is definitely irrelevant to the question (at best, there could be irrelevant #includes that merit a comment about their irrelevance), and the code will not compile without them (try it). I am not changing variable names, code structure, or anything vital to the question. I am simply making the question adhere to the guidelines.

Otherwise, the only valid response is a vote-to-close - which seems excessive since outside of the missing #includes, the question is perfectly reasonable. As the question currently has 4 upvotes and zero close votes (despite, again, containing broken code), it seems that the community implicitly agrees with this.

I simply want to make it explicit. Should this sort of edit be deemed acceptable? What if OP (a new user) does not return to edit in the missing includes? Should the question be closed then?

So questions must compile and work, in order to be considered on-topic questions.

No. The code must compile and work in author's environment, so that OP isn't asking the CR community to fix their code, which would be Stack Overflow territory.

But the code in the question itself doesn't need to compile straight out of the "ask question" box.

Of course, if the code in the question contains syntax errors and obviously won't even compile, it's broken code.

I don't do C++, but I deem #includes directives similar to C# using directives. Consider this snippet:

public async Task<int> DoSomething()
{
// do something async
}


If the OP's code doesn't include using System.Threading.Tasks;, this won't compile, because Task<T> isn't in scope. But does it make the question off-topic? No, it doesn't.

Compare to this:

public async DoSomething()
{
// do something async
}


Whatever using statements OP has, this method can't possibly compile, because the method is missing a return type - OP can't possibly have even tested their code, so claiming "it works in my environment" isn't even a possibility: that is broken code.

Asking that the code is working code makes a great filter for off-topic "what's wrong with this code?" questions, and weeds out the low-quality "please review this code I just wrote on a napkin" questions that contain blatantly broken code that the author couldn't even be bothered with compiling and running themselves.

A legit question that's merely missing #includes directives, probably had them redacted for brevety (a common reflex in users coming from SO) - of course, the code won't compile without these directives, but not having them in the question does not make the question off-topic with broken code.

Whether the code in the question box compiles all by itself and can be copied and pasted into your IDE without adding any directives and additional context, is irrelevant: if that were a requirement for on-topicness, we couldn't have tags like , and people coming here to post parts of their project that reference methods and types that are not included in the post.. and IMO that would be ludicrous.

That said:

• Should this sort of edit be deemed acceptable? Let's be consistent here, and leave code block edits up to the author of the question. Feel free to comment and ask that the missing #includes are (ooh) included (bah-dum-tish).
• What if OP (a new user) does not return to edit in the missing includes? That would be sad, but not harmful. The includes don't add much to the question anyway.
• Should the question be closed then? Nope. The code works, OP isn't asking about a specific programming issue.
• VTC both of these for stub/hypothetical code. – Der Kommissar Sep 14 '15 at 15:31
• @EBrown Just because it's not "the code, the whole code, and nothing but the code, so help you.... code" doesn't mean it's stub code. It can still be real code, directly copy+pasted, it's just only a selected portion of it. – Simon Forsberg Sep 14 '15 at 16:20
• @SimonForsberg I was referring to the two stub methods Mat's Mug posted... – Der Kommissar Sep 14 '15 at 16:20
• @EBrown Oh, right. Yeah, those would clearly be stub code :) – Simon Forsberg Sep 14 '15 at 16:21

I do agree with @200_success that it was better left as a comment. I don't feel that even something like #include should be added to the question by someone else. I would assume that the OP was already aware of #includes for his/her local code (you'd have to be a super beginner to not know about using the most basic ones) but felt that it wasn't necessary to have in the question. This could be because he/she wasn't aware that we prefer a compilable solution as-is, which of course would include the #includes.

If the OP never gets around to making this change, even after leaving a comment and possibly after giving a downvote, then just leave it at that. You should certainly still mention it in an answer, to which the OP may say that they were indeed left out intentionally. But other than that, they shouldn't be added to the question by anyone else.

• Do we prefer a compilable solution as-is? – Barry Sep 14 '15 at 15:57
• @Barry: Whenever possible, as it helps others review the code if it should be compiled and ran. Now, if non-obvious #includes were missing, such as custom ones, then that would be a problem. – Jamal Sep 14 '15 at 16:02

#include is a nice-to-have thing in a question. I agree with Mat's and Jamal's answers - that while the code won't compile without the includes, they are not necessary to make the question on-topic.

Additionally, editing them in is also "wrong" because it is the sort of thing only the question asker can know for sure, how it's done (hey, maybe they have their own strings.h!