r/cpp • u/collapsedwood • 4h ago
What do you think about modules?
I see lot of people don't like modules how they are now can they can be improved and what can be suitable solution what do you think?
6
Upvotes
23
u/TTachyon 4h ago
I think people's problem with modules is that they don't work (well) enough for that they need, either because they have to use old tools, or the new ones aren't good enough yet.
•
u/tartaruga232 MSVC user, r/cpp_modules 3h ago
They work and we use them. They are useful.
What's missing is, that you cannot do forward declarations of classes which are defined in foreign modules. You need to import the whole module, even though an incomplete type declaration would do. This creates unneeded dependencies and forces a lot of thinking.
•
u/javascript 3h ago
Modules only make sense in a world where C++ as a community is willing to break backwards compatibility. Having two import systems in one language is poor form.
17
u/Jakabxmarci 4h ago
We transformed part of our cosebase to use modules, but we regretted it afterwards mostly due to missing tooling support. CMake is mostly ok now, but distributed compilation, ccache, lots of libraries etc. doesn't work. If you do a smaller project without external dependencies then I'd recommend it.
•
u/steveire Contributor: Qt, CMake, Clang 2h ago
I won't really know what to think about them until libraries using them are packaged in linux distros. I'm interested to see how convenient they will be to use then.
•
u/holyblackcat 3h ago
The implicit
import A;in anymodule A;sucks, but otherwise the design looks ok to me. I wish compilers implemented the proper scanning for header units to make them usable.•
u/AvidCoco 1h ago
They don’t solve any problems (for me).
•
u/fortsnek274 3h ago
Pros:
import std.export. Hide implementation details.Cons:
•
u/azuled 2h ago
This is an outsider perspective, possibly. I don't use c++ very often, but I try to keep myself aware of how to use it properly, and every once in a while I write a project in it.
Modules seem like a massive improvement to the developer experience in theory. In practice it was a legitimate nightmare to get them working the last time I tried (June/July of 2026). I like the cleaner namespace separation, I like the cleaner import logic, I like the simpler boilerplate on every file. But trying to actually use modules took more time than the actual project took!
If they ever reach maturity, and ship with gcc/llvm+clang then yeah, I'm all in, I'll swap immediately, but it feels not ready yet.
•
u/kammce WG21 | 🇺🇲 NB | Boost | Exceptions 58m ago
I really like the power that the export keyword gives you that you don't really have with headers.
I just recently moved over to CMake 4.5.0 and now I can use import std pretty cleanly. So I'm pretty happy with the modules at this point. I don't think my builds are any faster, and I think they might even be a bit slower due to how clang does its dependency scanning, but I really appreciate the way that my code is looking, the way my code is organized, and the ability to selectively export particular symbols.
4
u/UndefFox 4h ago
My only problem with them so far is lack of tooling support. Qt Creator doesn't support them properly so all syntax highlight is broken.
Also the fact that modules will make more people use single file for everything. It's cool that you no longer have to repeat function declaration, but also reduces readability of the classes drastically...
•
u/eyes-are-fading-blue 3h ago
I gave it a go. It was too buggy back then. The interaction with headers was also a bit cumbersome to work with. I am waiting for tooling maturity at this point.
•
u/pjmlp 3h ago
I like them, and use them on hobby coding, only because my hobby coding is mostly focused on Visual Studio and Windows.
However we are still not there if you care about portable cross platform code.
I think they are the best example of what happens when ISO C++ keeps ignoring how the language magically transforms into executable code as part of the standardisation process.
-21
u/[deleted] 4h ago
[removed] — view removed comment