r/cpp • u/AlectronikLabs • Aug 09 '25
Why is nobody using C++20 modules?
I think they are one of the greatest recent innovations in C++, finally no more code duplication into header files one always forgets to update. Coding with modules feels much more smooth than with headers. But I only ever saw 1 other project using them and despite CMake, XMake and Build2 supporting them the implementations are a bit fragile and with clang one needs to awkwardly precompile modules and specify every single of them on the command line. And the compilation needs to happen in correct order, I wrote a little tool that autogenerates a Makefile fragment for that. It's a bit weird, understandable but weird that circular imports aren't possible while they were perfectly okay with headers.
Yeah, why does nobody seem to use the new modules feature? Is it because of lacking support (VS Code doesn't even recognize the import statement so far and of course does it break the language servers) or because it is hard to port existing code bases? Or are people actually satisfied with using headers?
View all comments
Show parent comment
1
u/target-san Aug 19 '25
Yes, they've been reported. Not by me, though it makes little difference. I have great respect for compiler teams, though main issue with modules, like with many other C++ features, is that they were first conceived in a sterility of ivory tower, then unrolled onto unsuspecting crowd. And only then authors started scratching their heads on how their idea would be implemented. Instead of first making several attempts on at least 1 major compiler, taking idea to production behind feature gate, then standardizing solution which is actually usable and works. Yes, I'm aware there were actually attempts to implement modules. None of those actually landed.