I firmly believe that it is perfectly possible to remain nice - polite, friendly, even welcoming - while still refusing to feed the troll, or the help vampire, or whichever other species of undesirable question-asker you are dealing with at the moment. For years, I've taken the approach of rattling off a short, impersonal comment and then closevoting the offending question. I think that this is better than just closevoting, because it sends the signal that at least someone did look at the question - if you get nothing but a closed question when you're new, you may have no idea how to proceed (yes, even though the system offers some tips in the close message, because the close message suffers from "I am an error message and therefore cannot possibly contain helpful information" syndrome).
Here is a sample of the kind of short, impersonal comment I tend to leave:
- We are not going to do your homework for you.
- This is a very basic question which would be better answered by a [language] textbook.
- To answer this question properly would require an entire chapter of a [language] textbook.
- Stack Overflow is not geared for helping people get started with large projects. Please come back when you have a concrete and specific question.
- I see many errors in this code. You should have a face-to-face conversation with your instructor about it.
- I do not understand what this program is supposed to do. Please explain.
- I do not know what you mean by "it doesn't work." Please be more specific.
- The bug is in code you have not showed us. Please read and follow the directions at https://stackoverflow.com/help/mcve.
- As described, this is not possible. Please explain why you think you need to do this and maybe we can help you find a better solution.
- This is a bad idea, because [reason]. Please explain why you think you need to do this and maybe we can help you find a better solution.
Now, I'm posting this partially just to put a stake in the ground on the side of "you don't have to be hostile to turn the bad questions away," but partially because some of the discourse flowing around the new code of conduct makes me wonder if any of the above comments might in fact be seen as hostile! So. What does the collective think of them?
Added after reading the first batch of responses: Several people have pointed out that the short and impersonal nature of these comments in itself makes them sound dismissive. This is fair and I'm going to think about how to avoid sounding dismissive. However, I think impersonality is a valuable tone to apply in this context, because it avoids mocking the person who posted the question (the comments that I tend to flag as "rude or abusive" are the ones that flirt with saying "this is a bad question and you're an idiot for not knowing the answer already") and at the same time it doesn't invite negotiation. I've seen people reply with "but I have a deadline!!!!eleven!~" more than a few times, I intend to come across as someone on whom that will not work, and I really hope that's not seen as unacceptable.