Benefit of not having the imports:
- Shorter code, so less scrolling.
Harm of not having the imports:
- Code that doesn't work out of the box, it's up to the reader to fill in the details.
No, code without import statements is not more readable. The imports are grouped in a block at the beginning and it's absolutely immediate to skip them if you don't need to pay attention to them. But when the imports matter, it's vital that they're present.
Conversely, not having the imports there makes it harder to test the code. Even if I'm thoroughly familiar with the language, I don't want to hunt down which libraries are needed.
Compilable code is always preferable. In the words of the help center: we encourage a complete, tested example.
Missing imports should be edited in if they're obvious, and if they're not, then the question should be closed as unclear with a request for the asker to post compilable code, complete with imports.
Now, when it comes to editing somebody else's question, there's another factor to consider: it's risky to edit code, because it might change the problem. Editing code in questions should only be done when it's absolutely certain that it won't happen to solve or move the problem around. Generally speaking, in a question, only edit for indentation and the like.
So when reviewing suggested edits:
- If the edit removes necessary imports, reject.
- If the edit removes superfluous imports from a question, reject unless it is absolutely completely obvious that these superfluous imports won't be causing any trouble such as name shadowing.
- If the edit adds imports to code in a question, proceed with caution. If the imports are correct and complete, and you're sure that the problem is unrelated to having wrong imports, accept. If the imports look plausible but you aren't familiar enough with the language to be certain, skip. Otherwise, reject.
- If the edit modifies imports in an answer, accept if the change is correct (adding necessary imports, removing superfluous ones), reject otherwise. If you aren't sure, skip.
import
is overshadowed by important,include
by include(non-programming)/including/included.