4 ms·
Modules, dammit! Year after year, decade after decade we have been waiting for modules, and instead we are fed with nothing but minutia.
by fnj 10y ago
Modules, dammit! Year after year, decade after decade we have been waiting for modules, and instead we are fed with nothing but minutia.
- Koshkin 10y agoI am curious, what would having modules give us that we could not have with classes and namespaces? (I understand that in a language like Java a module, a class, an interface - are all different things. C++ is different in this respect, as it only provides a mechanism and not a policy.)
- ovao 10y agoThe main appeal for me is the possibility for substantially decreasing compile times. The current include system really precludes a lot of work in this area.
- pjmlp 10y agoFaster compilation times and metadata for improved tooling.
- humanrebar 10y ago#include is literally expanded to the contents of the file you are including. And that works recursively until the compiler has one giant source file that recursively includes the text in all the headers you included. And in that process all preprocessor macros are also expanded. This happens for every source file that is compiled. It would be nice to skip all that and just have some standard way of listing the already-analyzed contents of a the modules you need. In addition to the obvious performance improvements this would give compilers, this really cuts down on the complexity that third-party tools need to deal with to work well with C++ code. The quality of tooling for C++ has historically been stymied by the complexity of analyzing the code itself. Modules are a huge step in the right direction for helping with this.
- pg314 10y agoAs an illustration of how much code gets included (on macOS Sierra): $ echo "#include <iostream>" > foo.cpp $ g++ -E foo.cpp | wc 37799 104779 1280834 Including just iostream in a file means the compiler has to process 37799 (!) lines. For comparison, a C file including stdio: $ echo "#include <stdio.h>" | gcc -E - | wc 456 1638 20880 That still looks bloated to me, but is about 60x times fewer bytes.
- stirner 10y ago$ curl https://git.musl-libc.org/cgit/musl/plain/include/stdio.h | wc 203 630 5231
- ziotom78 10y agoFaster compilation times. A good C++ compiler as fast as Free Pascal's (which has units, much similar to modules) would be a killer.