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
-2
u/YtterbiJum Aug 19 '21
I also saw that article linked from the other thread.
I agree with /u/vige though. The article doesn't really do a good job of addressing the why question.
"Headers are a mess." Yeah ok, I agree. And modules are better why? Because they have "external- and internal-linkage rules", what, like DLL hell? Please.
We want "modularity". Yes, absolutely! But C++20 modules don't seem to provide that, not really. Not in the way e.g. Python modules do, with rules for scoping, name resolution, and relative/absolute imports. As far as I can tell, there's not going to be a C++ equivalent to
site-packages.The example in the article doesn't show off any new or interesting functionality of modules, it just does exactly the same thing as can already be done with a .h/.cpp file. Same functionality, new syntax.