-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preview of clang-format changes and CI #97
Conversation
The original formatting of the code was heavily influenced by the practices at the company I was working for at the time. I think we should pick a format that requires as little configuration override as possible. |
What exactly do you mean by that? As mentioned the config is generated by
That one was generated the same: Start from some config then start changing settings so the source code formatting stays as similar as possible. You can however compare the resulting style and choose one or the other. |
I guess I meant let’s dump the config and that’s it, try not to override anything if that’s possible? |
799c6a6
to
805e3b0
Compare
Then the question is: What is "the config"? clang-format has predefined styles: LLVM, Google, Chromium, Mozilla, WebKit, each is an own set of settings. The config here is based on one of them (can't remember which) but adjusted for 2 things: minimizing horizontal and vertical spacing (e.g. the removal of spaces in parentheses or putting short functions [mostly getters] onto single lines) while maximizing readability, especially related to control flow: braces on new line, block indented, however also use I don't see a reason "to not override anything" from the default styles. The file has the same size. Everyone has a different taste and I guess each of those configs is simply adjusted to be similar to whatever they used when they introduced clang-format. I see most styles use a TabWidth of 8 which I find wasteful. Some don't have a column limit or use only 80 which IMO is to small for modern systems. 120 is a good compromise I added a commit with the styles without changes (no file changes though) and the diffs to the current style is: format.txt Diff to e.g. the nowide format:
I mean that's the whole point of clang-format: You can adapt to the way you think is best. Just check the code for something you don't like and change it in the format file. Or for this you can check the diffs and decide which change you'd like to revert. Hope that helps |
Yes it doesn’t matter, as long as it can be checked by the CI and applied with one command on the whole source tree. |
I'm wondering what the reasoning behind this is. Is it to make it match an existing style so people are more likely to be used to it? |
It’s more I don’t think it’s worth spending time tweaking a config. I assume the predefined configs all make a good job at providing a set of meaningful coherent rules and I’m sure it’s easy to mentally adjust to any of them. |
Ok, I updated it based on the Mozilla style (closest to the one I had first) with the following changes and reasoning:
See https://releases.llvm.org/10.0.0/tools/clang/docs/ClangFormatStyleOptions.html for details on the options. As you can see most changes are either adjustment for wider columns, new additions to clang-format or for increased consistency of overall rules (like: Brace goes on new line) What do you say? |
Works for me, thanks! |
Great! Closed this then and will rebase and apply when #88 is ready to be merged or better after it is merged due to the amount of changes coming in. Final suggestion here: Especially for the long parameter list tests the formatting is suboptimal as with the Let's continue the rest in #88, e.g. I need to know when to apply this formatting. |
NOT MEANT FOR MERGING
Once this is approved the style will be applied to #88 instead as otherwise conflicts would be unresolvable
@mat007 as you wrote at #88 (comment) you don't really care what style is used as long as it is consistent. I therefore imported a clang-format style from another project and only slightly modified it.
Not AFAIK. There are 7-8 libs with clang-format files and they don't look complete, so it's hard to tell...
When I took over maintenance of Boost.Nowide I created a style file that closely matches the style of the author. So there are a few options here:
--dump-config
so everything is explicit and upgrading clang-format is easier)I'd go with the last option so here a few key points:
{
except for namespace and short blocks (put on single line)namespace mock { namespace detail {
, short of syntax likenamespace mock::detail {
@mat007 Just check the above points and the changed files and tell me where you'd like a change. E.g. I don't like the spaces in brackets and it seems to not be used in Boost, e.g. https://github.com/boostorg/outcome/blob/master/include/boost/outcome/basic_outcome.hpp. But as you had them I can add them back. Can be adjusted separately for conditions, functions, calls, templates if wanted