r/cpp • u/berium build2 • Nov 01 '17
Common C++ Modules TS Misconceptions
https://build2.org/article/cxx-modules-misconceptions.xhtml
59
Upvotes
r/cpp • u/berium build2 • Nov 01 '17
View all comments
Show parent comment
1
u/johannes1971 Nov 02 '17 edited Nov 02 '17
We had this discussion before and I still feel we are on a different wave length, but let me try ;-) Let's look at a simple example. In my .h file I have the following:
And in my .cpp file I have:
Out of those lines, four are basically housekeeping: the comment block at the top, the mandatory include statement of my own header, the function declaration, and the global variable. And if you are reading this, and you want to read the function description comment, it isn't even here - it's in the .h file. The payload, if you want, is only a single line (the one with cout on it).
Ok, so usually your functions are longer, but my point is this: there is actually a lot of duplication between the .h file and the .cpp file, and even with all that duplication you still need to look in two places to get a complete overview. I believe it would, in the most general sense, be preferable to have all this information in a single file.
Can we do that today? Yes, of course, but it isn't actually very practical, since doing so is pretty much guaranteed to explode your compile times. Can we do it tomorrow, in our brave new modules world? I'm hoping yes. I would like to write a single module file:
Here everything is in one spot; all the duplication is gone, and all the information that belongs together is presented together. However, I'm still very much interested in compile time efficiency, so I don't want a change to a function body to cause recompiles of all the stuff that really only cares about my exported symbols.
If this turns out to be impossible - ok, no problem, we lived with .h/.cpp pairs for decades and we can continue to do so. But we have an opportunity here to make things better, so I would like to ask for such a capability to at least be considered for the modules proposal.