r/cpp • u/tartaruga232 MSVC user, r/cpp_modules • Apr 26 '26
Code Examples From an App Using C++ Modules
https://abuehl.github.io/2026/04/26/code-examples-from-an-app-using-modules.htmlThis demonstrates usage of our recommendations for using modules:
- Prefer small modules
- Only use partitions if you really must
- Avoid using internal partitions
The intention is to show some real code for context of discussions about using C++ modules.
My goal is not to sell modules. If you prefer not using modules: Use header files. There are good reasons to continue using them.
For me, C++ source code is an asset. The intrinsic value of code using modules is higher (lower entropy), as modules are a higher abstraction, compared to header files, which are basically just the pasting of C++ code into translation units (I've done that for ~36 years now).
Using C++ modules comes at a cost though. Understanding modules requires a certain level of understanding, which isn't needed when using the simple model and tradition of header files.
24
u/Jovibor_ Apr 26 '26
Worst suggestion out of all.
import std;is laughing at you here.Use modules of any size you need. That's the only correct advice on this matter.
4
u/yeochin Apr 27 '26 edited Apr 27 '26
Please don't go around giving this incredibly bad advice. Having seen module code bases at scale you don't want small modules at all. Small modules are a pain to merge together. Big modules are easy to split. The most successful libraries and implementations are those that boil it down to a single import statement for a rich set of functionality.
With the state of existing compiler toolsets and your handy autocomplete - smaller modules only increase the likeliness that you're going to run into a internal compiler error, or a broken autocomplete database.
3
u/manni66 Apr 26 '26
Your recommendations give the impression that you yourself haven't really understood C++ Modules yet.
2
u/Daniela-E Living on C++ trunk, WG21 |🇩🇪 NB Apr 27 '26
My experiences from the code for a real, huge machine in production at a steel mill (and many more projects, too) sit on the opposite end of the spectrum. Hence I'd rather think of
0
u/tartaruga232 MSVC user, r/cpp_modules Apr 26 '26
Fun fact: I now managed to eliminate that
Core.Main:UndoerImpinternal partition and turn it into a normal module. That was our last internal partition we had...For example Core/Main/Undoer/UndoerFunctions.cpp now imports the new
Core.UndoerImpinstead of:UndoerImp.