r/cpp • u/collapsedwood • 3d 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?
29
Upvotes
52
u/TTachyon 3d 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.
40
u/Jakabxmarci 3d 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.
17
u/kammce WG21 | 🇺🇲 NB | Boost | Exceptions 3d 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.
33
u/tartaruga232 MSVC user, r/cpp_modules 3d 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.
27
u/javascript 3d 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.
13
u/fortsnek274 3d ago
Pros:
import std.export. Hide implementation details.Cons:
9
u/holyblackcat 3d 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.10
u/UndefFox 3d 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...
4
u/azuled 3d 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.
4
u/Daniela-E Living on C++ trunk, WG21 |🇩🇪 NB 2d ago
With projects in production (like e.g. from our company), I see Modules as kind of 'legacy' now. Hence, it needs very solid and convincing ideas for potential improvements to convince me of changing the standard. On top of that: you need to convince the implementers and tool suppliers to collectively agree on that, too.
4
u/Jakka47 2d ago
Once you've worked out how to use them, you'll never want to go back. I'm working on a codebase that uses a mix of modules and includes. Eventually it will all use modules. Had a few issues with compiler bugs at the start, but very few problems now. There are a few things you can't do with modules and some parts of the code were riddled with macros and conditional compilation, and had to be rewritten. TBH, it was worth it just to clean it all up. Some things should just not be allowed, but I do sympathize if you're stuck with legacy code you can't modify.
5
u/steveire Contributor: Qt, CMake, Clang 3d 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.Â
6
u/AvidCoco 3d ago
They don’t solve any problems (for me).
3
u/a_jasmin 2d ago
For me the appeal is to stop having to maintain pairs of .cpp and .hpp files and do away with proprietary pre-compiled headers mechanism.
Current tool chains and libraries aren’t quite there yet unfortunately.
3
u/mjklaim 2d ago
I've been using modules for years in my personal projects (mostly games or plugins that are parts of game projects) using build2. I will probably never get back to includes as long as I can avoid it.(I'm ok using dependencies that are not modularized, I can modularize them specificallly for the project.
The short story: I'm very happy with it as long as I don't hit compiler crashes (ICE) or bugs specific to modules, but these days they are rarer. I use msvc and clang, but I've also used gcc.
I can use modules because my projects are isolated, but the choice of using them depends a lot on the tooling and if you're adapting an existing project or not, and if you expect your "users" can use an adapted toolchain, if you make libraries.
2
u/ConsumeUranuim 2d ago
I wrote some of my own tooling to work with them. Which definitely made them much more enjoyable to work with, to the point where my new codebases are almost only module-based now.
2
u/eyes-are-fading-blue 3d 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.
2
u/kamrann_ 2d ago
The unfortunate thing is that modules could solve a lot of problems for a lot of people, in so far as it's really difficult to overstate just how negative the effects of the preprocessor are on tooling. You might think headers work fine and believe that you rarely if ever are affected by ODR violations, but even if that's the case, there would be so much better tooling if not for all the pain that the preprocessor adds to the mix.
But of course, deprecating headers is a pipe dream. Modules feel like the perfect demonstration of how the need for backwards compatibility just cripples the potential of most new additions to the language.
0
u/pjmlp 3d 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.
1
u/saxbophone mutable volatile void 1d ago
They seem really great on paper but they've been thoroughly hobbled by lack of vendor support.
-1
u/Sopel97 2d ago
made me switch to rust
because it uncovered how messy the language is and that there is no path to fix that
-2
u/NilacTheGrim 2d ago
Unneeded and stupid. I quietly hope they will just prove to never be viable and that they go away forever eventually and get removed from the language in like c++2037 or something.
0
u/all_is_love6667 2d ago
I don't know that much about modules.
I just know they're not really mature now, and apparently they don't really speed up compilation that much.
I sure hope it's going to improve in the future, it's probably a matter of how compiler engineers will update their compilers.
0
u/ir_dan 2d ago
Haven't used professionally. Annoyed about incompatibilities with headers, since modules aren't even close to being standard across compilers, and many projects are and will use headers for a long time. Not solving any real problems yet.
0
u/umlcat 2d ago
To be honest, I have a lot of trouble understanding how they work ...
0
u/megayippie 1d ago
They have so far been a great time sink with zero use-cases for. It seems like a completely failed idea in practice, honestly. I really want the promise of "import std" but as long as the support is not uniform in the major 3, and things like mixing includes and imports work, it is dead
-1
u/el_toro_2022 1d ago
if you look at the equivalent of modules in nearly every other language out there, the implementation is much cleaner. Haskell, Rust, Ruby... very usable.
The problem with C++ is that it still carries the legacy of header files and backwards compatibility. So it makes the implementation of modules that much more complicated, which is why it has not settled yet after how many years?
All my current C++ projects are header-only, which eliminates the messiness of splitting up your classes and structs into .hpp and .cpp files, which works and is fine for smaller projects, but for bigger ones can result into long compile times for the translation units that now must pull everything in again for even a small change somewhere.
There are ways around that hit, of course, but results in even more complexity in the build process.
I love C++, but the header files has been the biggest wart in my experience.
-22
u/[deleted] 3d ago
[removed] — view removed comment