7 ms·
I'm talking about clang-format, a formatting tool for C and C++ code, which has nothing to do with compiling your code with clang. You can use it with any compi
by BeeOnRope 7y ago
I'm talking about clang-format, a formatting tool for C and C++ code, which has nothing to do with compiling your code with clang. You can use it with any compiler.
That said, the title is still a lie in that clang-format is not really at a fault here at all: clang-format triggered the issue on my codebase, by sorting header files, and this in turn triggered a libc performance issue.
So as I initially say it, a commit which purely clang-format 'd my codebase caused a massive regression - but the full story is doesn't implicate clang-format at all, really.
- glandium 7y agoThe title would be a /little/ clearer with a dash between Clang and format.
- ndesaulniers 7y agoOr "header inclusion order may affect performance." If someone points to this as a reason not to use clang-format...
- BeeOnRope 7y agoGood point, I put a hyphen a few places but not everywhere nor in the title. It seems hyphen is definitely the standard though. Fixed now [1], although the HN title will remain hyphen-free free I guess. --- [1] https://github.com/travisdowns/travisdowns.github.io/commit/95c6788e011eaa9638e12223d6d7dbd0465e5d8f https://github.com/travisdowns/travisdowns.github.io/commit/...
- dleslie 7y agoclang-format reordering includes is a terrible behaviour. It would break many C/C++ projects.
- glandium 7y agoIt's optional, although it's enabled by default in the LLVM and Chromium styles.
- dleslie 7y agoThat's a bizarre optional feature to have; it's tantamount to having a "blindly reorder logic" function that sorts your source alphanumerically.
- defap 7y agoNot really too bizarre. Header files should include or declare everything they need; they should not introduce include-order dependencies. Listing your includes in lexicographic order is a good way to enforce header completeness.
- dleslie 7y agoIt is by convention that C/C++ headers rely on preprocessor state to determine what blocks to reveal, macros to use, et al. It is quite common to have an auto-generated configuration header, for instance; or a precompiled header; or optional headers that, when present, mutate the behaviour of other headers. Every time you run a configure script for a C project there's a good chance you're interacting with code in this way.
- lorenzhs 7y agoYeah, and if you want to use clang-format include reordering in such a project, you should read the docs for clang-format's "IncludeCategories". It allows you to separate your includes into blocks by providing regexes and associated priorities. Alphabetic sorting is done only within a block. It's not like clang-format was written by idiots who never used the language before. Maybe read up on what the tool actually does before you get all mad at them?
- dleslie 7y agoI'm not mad? I think it's a harmful anti-feature that's worthy of criticism.
- glandium 7y ago