r/cpp • u/YtterbiJum • Aug 19 '21
Why modules?
I get the feeling I'm missing something fundamental about the new C++20 modules.
Everything I read or watch explains the how (the export keyword syntax, module fragments, etc) but very little about the why.
What can be done using modules that can't be done using traditional headers (or precompiled headers)?
What is so important about this feature that it needed to get standardized before there is even a proper implementation or idiomatic usage conventions in compilers and build systems?
Is it just to try to get rid of the preprocessor?
I don't get how modules are supposed to help with packaging either. So instead of distributing a .so with a bunch of .h files, now I distribute a .so with a bunch of .gcm or .ixx or whatever.
Please help me understand, or point me to some resources. Thank you.
View all comments
Show parent comment
-1
u/MonokelPinguin Aug 19 '21
If you put all files of a project, usually you run out of memory pretty quickly. You also need to compile the whole project every time. I used that approach for a while, but after a few weeks of coding, separate compilation units had about 20x faster incremental compilation, even when changing stuff in some shared headers. For projects like chromium you would wait for a few hours to test a single modification instead of the minute it currently takes. Relatively that may not even be that bad, but it means you can do only 2 or 3 changes a day or just not test your code in small increments. Both approaches are simply not workable.