Re:Clang Format Tanks Performance
by lilyball on Wednesday November 20, 2019 @03:44AM
(#21582182)
Headers really shouldn’t be affecting each other. Header order shouldn’t matter. The fact that it does is arguably a bad design flaw in C/C++, although the C modules system pushed by Apple fixed this.
[ Parent
| on HN ]
Tooling developers don’t get to say “it shouldn’t matter”. It does matter, so the tools should account for this.
clang-format does account for this: if you break your includes into groups with blank lines, clang-format will sort within but not across the groups. That is, clang-format offers a crude but simple API to the programmer to express which headers have order dependency, and which don't.
Given that headers can have order dependency, it is sadly part of a C++ programmer's responsibility to know which do, just as it is their responsibility to know which functions have side-effects, etc. If they are using clang-format, it is then their responsibility to communicate this knowledge to it.
The simplest way to communicate that this anti-feature is unwanted is to add this to your clang-format:
SortIncludes: false