-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Clang format #3553
base: master
Are you sure you want to change the base?
Clang format #3553
Conversation
In general I'm all for this, however I have held back on even looking into it because there are lots of cases where I think a slightly lax adherence to the rules results in more readable code. Perhaps we can address that through configuration. So let's discuss. I kinda feel that 160 is too wide. I often feel that 80 is too narrow. Maybe something more like 100 would be better. We have some cases of things like int x=something, y=somethingelse, z=blah. I never do this myself, but when I see it, I want each of those on a separate line and as we see in this output, clang-format will merge them onto 1 line. So the answer there might be to not use the comma separated definition style. This also reorders the includes... I was under the impression ours were to go first before the system includes... I'll have to re-read the best practices on that. I eagerly await other's comments. |
I am a bit worried it would lead to bikeshedding. I think you can set it when checking to not error for certain formatting issues. Another option is to just run it once to get the code consistent and trust in the reviews to keep it. You can use comments to disable the checker/reformat if needed in a few places but that should probably be kept to a minimum. I don't see any settings about the variable wrapping. Style guide just says:
For the includes, it is fairly configurable, and is using the Google preferred order:
|
So, here are my two cents: I'm all in for this. I routinely press the auto-format shortcut in my IDE and just not really spend thoughts on formatting while writing code. IMHO that frees up quite a bit of brain processing power. If we have now the chance to codify and make these rules distributable, that's a great step forward. Some more concrete thoughts on the points mentioned before:
Just as a sanity check, it might be a good idea to run clang-format on files which have been added or rewritten completely "recently". Those should come out pretty much unchanged, if the clang-format settings match the formatting expectations. The sample size is limited, but I guess better than nothing... So that would be:
Happy to discuss this further. |
So here is the above listed files (skipping test). I've adjusted it to 100 columns, and adjusted the include ordering, although I don't think I can group the conditional includes separately the bottom, external library headers (anything with a prefix directory) will be at the bottom. If these files are closer to the style you want, I can start making adjustments to get the formatting closer. |
I'd say that in general I like the current settings and resulting formatting. The only comment I have at the moment is that when we a function with a lot of parameters, instead of two or three long lines, I prefer it to just give each parameter it's own line. Makes adding/subtracting parameters a little easier to read in the diff. I don't know if that is possible, but if it is, then I would do that, and then merge this. |
… for wrapped lines.
I've pushed that change as a diff to make it easier to review. I'll rebuild the pull request based on master when ready. |
Here's an initial clang-format style file. It uses the Google Style (found in the Coding Standards wiki) as the base but I increased the column width to 160 based on some of the lines in the existing code base.
The second commit is an example of letting clang-format re-write
src/zm_stream.*
(viaclang-format -i src/zm_stream.*
)For those not familiar with clang-format, there is a built-in command in git,
git clang-format
, that can check or fix the lines you've edited, or a patch range. There are plugins for various editors and can be integrated into git commit hooks and/or the CI.Depending on if anybody has any large work outstanding, it might be better to wait to reformat the code base just before or just after a release. I could also work through it a bit more slowly, starting with files that haven't been updated in a while.
https://clang.llvm.org/docs/ClangFormat.html
https://clang.llvm.org/docs/ClangFormatStyleOptions.html