This is basically a continuation of "Why don't languages auto import everything?" but with a slightly altered premisse:
Say we have a language like C++ / python that uses namespaces to distinguish functions and classes from other modules, would it not in theory be possible to leave out all the includes / imports and have the compiler automatically resolve the tokens back to the corresponding library?
The way this would work is that the build system puts the dependencies into the compilers context, and the compiler will search through a complete index of tokens directly instead of going through the imported modules.
The imports can sometimes be resolved by modern IDE's, but this is never at the language level and even for modern languages you need to do it. Why though?
Consider this simple case:
#include <iostream> int main() { std::cout << "Hello World" << std::endl; } In 99% of the cases the user wants to import std::cout from iostream. While C++ can't necessarily guarantee that there isn't a competing std::cout out there, a language designed with this in mind could potentially (hypothesis). So why isn't it done?
A huge benefit would be that refactorings would become so much easier, since you don't have to flip through all your dependencies to check which ones to import and which not (even of course LSP's will make that easier). And at the same time you're never importing too much, only the tokens that you really need...
The question is: Is it necessary or just tradition?
cout, I'm not as sure that it's easy when you consider the entire family of things that may be pulled in by a simple-looking#include <iostream>, especially considering that (currently) the include is purely textual and performed by the pre-processor (so the existence of it is gone by the time the compiler takes a crack at it).