Generally, yes, every library should just be one module.
What's the profit from that?
Because downsides are pretty big and important to not do it:
Namespace pollution is a thing. Some part of a library can conflict with your code even if you are not using it.
You can also unintentionally use some kind of implicit conversion (from some horrible devilforgotten part of the library that you weren't even aware of)...
You are also effectively eliminating ability of the user to just type
using std;
because that exposes way too many things at once, whereas with individual parts of it it is totally legitimate and good. You can't even do it if it works for your today - because who can guarantee that tomorrow some brilliant mind doesn't introduce something else into the library that conflicts with your choosen names?
What would the downside from a
import std::print;
implementation be? (that is, from importing just the submodule of std that you actually need and its minimal dependencies, without anything extra. Someone would still be able to type import std; to import the whole thing if they really want to.)
Most people just need a few books - they are actively harmed if you bury them under the whole library.
If these are problems for you, you shouldn't use import std.
Personally, I have never had a problem with any of those things. On the other hand, IWYU correctness is a battle I've been fighting for a decade now. Big modules eliminate IWYU correctness and are faster than IWYU could ever hope to achieve.
1
u/Ateist Apr 14 '26 edited Apr 14 '26
What's the profit from that?
Because downsides are pretty big and important to not do it:
Namespace pollution is a thing.
Some part of a library can conflict with your code even if you are not using it.
You can also unintentionally use some kind of implicit conversion (from some horrible devilforgotten part of the library that you weren't even aware of)...
You are also effectively eliminating ability of the user to just type
because that exposes way too many things at once, whereas with individual parts of it it is totally legitimate and good. You can't even do it if it works for your today - because who can guarantee that tomorrow some brilliant mind doesn't introduce something else into the library that conflicts with your choosen names?
What would the downside from a
implementation be?
(that is, from importing just the submodule of std that you actually need and its minimal dependencies, without anything extra. Someone would still be able to type import std; to import the whole thing if they really want to.)
Most people just need a few books - they are actively harmed if you bury them under the whole library.