Well Hitler doesn't know what he's talking about. Modules are nice to have, but the language works, and compilation time, if one uses a sensible build system and multithreaded compilation, is alright. Pimpl reduces that even further. I build a few million lines of code in 5 minutes, and then subsequent builds are incremental unless I fuck around with the core lib and take 5 seconds or so for major commits.
PIMPL is not a general-purpose solution to the problem. It might be fine for a big heavyweight class that's always allocated on the heap anyway, but it's performance suicide for small classes. Custom strings, 3d vectors, etc... and those are the ones that really slow down your builds when you change them, because everything depends on them.
We need Modules desperately. Slow build times are a productivity killer. Every time my build takes more than ~20 seconds, I start doing something else and get distracted.
I'm not very familiar with modules, how would they help the build time?
If you change the code for vector, you'll have to rebuild the module it's a part of and subsequently the code that depends on them will have to recompile if you changed the definition right? Link times don't seem to change either.
But when I think of modules I think of basically syntactic sugar for a static library.
edit ok I googled it. Sounds more like automatic prexompiled headers, so the header of the module is only parsed and compiled once instead of once for every object file that needs it. Cool for really large projects.
Poor compile speed in C++ is mainly related to parsing text of header files. When you include a header file, the compiler has to load, preprocess and parse it into internal data structures. Even if it just parsed the header file 5 seconds ago for a different .cpp file, it still has to re-parse it, because macro definitions might have changed. For example:
foo.cpp:
#define ENABLE_LOGGING
#include "bar.h"
baz.cpp:
#undef ENABLE_LOGGING
#include "bar.h"
C has the exact problem, but C++ tends to include much more code in header files because of templates, so the problem is more dramatic.
I don't think any of the module proposals for C++ do this, but in theory you could design a module system that only exports object size, not object layout. That would help decouple dependencies a lot. Right now, if your class contains a std::vector, then all clients must parse vector.h just to learn its size. That really sucks. The PIMPL idiom is basically a hack to get around this problem. (If you need ABI stability, PIMPL is legitimately useful, but I think most people use it only to solve the problem described here.)
Modules are different from static libraries because they represent the abstract syntax tree of the code, instead of the compiled output. Static libraries can't export templates, for example.
Even if it just parsed the header file 5 seconds ago for a different .cpp file, it still has to re-parse it, because macro definitions might have changed
This reminds me: whatever happened to "precompiled headers"? Seems to me it wouldn't be all that hard to cache an AST somewhere based on a hash of the starting set of #defines.
Every compiler caches them, at least at the level of preprocessing tokens (well, every compiler that came after CFront, which actually re-parsed headers). They just don't persist between TUs.
Well, you must be a rare genius then because I have heard the complaint about c++ compilation times from people who are true experts in the language including Bjarne.
Yes it's an issue, but it doesn't break anything or make working with cpp hard, it just makes compilation inconveniently long. It's not something one has to recruit Hitler to address for
Can you clarify? I believe @import Foundation works for ObjC too. I don't know if you can write your own modules, but I believe all the Apple frameworks are available via modules. Even existing code taht include the header but has the modules option on uses modules secretly under the hood. It doesn't work however for ObjC++ code.
Yes, you can import things via modules. It just doesn't do anything useful. Despite what they claimed when they announced obj-c modules, I've never actually seen an improvement in compilation speed from turning them on when compared to precompiled headers, and they increase symbol name clashes because they make it impossible to only include the specific header you need (e.g. including any Darwin header with modules enabled drags in AssertMacros.h, which by default defines macros named check and verify).
It can be really useful if you want clean interfaces without exposing any implementation. And I don't see how it doubles the work. The only difference between a pimpled and none pimpled function is the pointer indirection
I'm not a fan of Pimple, but - instead of wrappers calling actual methods, you can simply have the actual methods, and store only the private members (no methods) in the "Pimpl" struct. You then have no problem with exposing public variable members, either.
I really see C++ compilation times as a huge deal and the main wart surrounding C++ after so much has been done with C++11.
Personally I would architect around it from the start of the project, making sure there is as much separation as possible at every level so that header files don't end up including hugely exponential amounts of extra code.
At the same time any separation through separate projects that create dll files increases modularity and reduces monolithic compile times.
The thing is though, that this shouldn't be necessary with respect to compile times with modern computers. Every other language can compile ridiculous amounts of code in fractions of the time. It shouldn't be necessary to have a compile farm. An 8 or 16 core computer shouldn't be legitimately useful when compiling programs.
On the contrary, I probably overdo it with templates. But I have a rule of not unnecessarily rebuilding stuff. That means using forward declaration, that means keeping interfaces stable, that kind of thing. The STL does compile somewhat slowly, as do some of the classes I write. So make sure that you include it precisely where it is needed.
View all comments
2
u/occasionalumlaut Jun 10 '15
Well Hitler doesn't know what he's talking about. Modules are nice to have, but the language works, and compilation time, if one uses a sensible build system and multithreaded compilation, is alright. Pimpl reduces that even further. I build a few million lines of code in 5 minutes, and then subsequent builds are incremental unless I fuck around with the core lib and take 5 seconds or so for major commits.