-
Notifications
You must be signed in to change notification settings - Fork 13
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
Add .clang-format #599
Add .clang-format #599
Conversation
To try it out, checkout this branch, and call clang-format <file-name> -i to have it reformat . |
363dd56
to
9e535d9
Compare
After a bunch of testing, this Clang Format configuration is quite close to what is done _most of the time_ in this repository. The only thing I've found which it breaks consistently is when an UDT is instanciated inline, the braces are split: ``` struct bar {} foo; ``` becomes ``` struct bar { } foo; ``` and (maybe worse cause that's how it's often written in this project) ``` struct bar {} // comment foo; ``` becomes ``` struct bar { } // comment foo; ``` . This along with disallowing the rest of multiple operator seperated items in argument position to flow to the last line if they are neccesary to split giving: ``` throw invalid_argument("Adiar requires at least " + std::to_string(minimum_memory / 1024 / 1024) + " MiB of memory"); ``` instead of ``` throw invalid_argument("Adiar requires at least " + std::to_string(minimum_memory / 1024 / 1024) + " MiB of memory"); ``` Except for that, all changes I've observed it making is within "normal" for the codebase.
9e535d9
to
cbe623f
Compare
Great work. That would definitely be a great addition - especially when others than me actually want to contribute. I'll play around with it and add some discrepancies below. |
Conflicting with EmacsOverall the GNU style is Emacs-compatible. So, if there are settings in the GNU clang-format file that conflicts with this then the GNU setting would be the safest to use. The exception would be all settings that can be resolved with a 'newline' character (Emacs does not add newlines, but has an "intelligent" indentation). In general, I'm ok with being more GNU-like at the compromise of some parts of the codebase (which I indented manually). Note, specifically indentation to make binary operations (e.g. Indentation of Member list
Indentation is here 4 spaces rather than 2. Comma in Member Initialisation List In src/adiar/internal/data_structures/levelized_priority_queue.h
Here, Emacs would de-indent all but the first member initialisation by two. This is why, I move the Unexpected 4-space indentations In src/adiar/internal/algorithms/reduce.h. Is this related with trying to align the statement with
And in src/adiar/internal/algorithms/prod2.h. Here, it adds an odd additional indentation.
And in src/adiar/internal/data_structures/levelized_priority_queue.h
Emacs would in all of these cases only indent the line with two spaces. Struct Initialisation In src/adiar/statistics.cpp, the indentation on the struct misaligns with Emacs.
The same also applies to initialisation lists. For example, Odd indentation for function call In src/adiar/internal/data_structures/levelized_priority_queue.h.
Emacs would in this case even with the 'newline' added indent it up to the Possible CompromisesAligning Operators/Assignment The following is an example (from src/adiar/internal/algorithms/pred.h) of how Emacs usually aligns things. Personally, I prefer the setting you have set. I just want to note, that if you cannot fix anything else without breaking this, then I am ok with that.
|
Other (Personal Preference)One-liner Constructors In src/adiar/builder.h
In src/adiar/exec_policy.h
Can the constructors always have line breaks after the arguments and the member initialisation list? Line Breaks on Binary Operations In src/adiar/exec_policy.h.
Similarly, in src/adiar/statistics.cpp
If there is a line break, then I would prefer it breaks all of them. The idea being, that the 'vertical' dimension is the conditions and the horizontal then their content. But, it is fair, if that is not possible. Nested Ternaries In src/adiar/internal/algorithms/nested_sweeping.h.
While not a pattern-matching formatting, it is very readable. I like it! But, the indentation should probably only be 2 rather than 4 to be consistent with the rest. Doubly-braced Initialisation In src/adiar/internal/node_writer.h, the
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I have exhausted all observations on its changes (noted above). Overall, it does a great job! Most of the changes makes older code align with styling I've adopted recently but not applied everywhere.
If any of the above can be addressed, then that would be greatly appreciated.
I have looked into how to integrate clang-format into CMake. I have pushed the changes to do so (no conflicts with the config, so you can easily rebase any fixups. |
510222e
to
31f6796
Compare
After a bunch of testing, this Clang Format configuration is quite close to what is done most of the time in this repository. The only thing I've found which it breaks consistently is when an UDT is instanciated inline, the braces are split:
becomes
and (maybe worse cause that's how it's often written in this project)
becomes
. This along with disallowing the rest of multiple operator seperated items in argument position to flow to the last line if they are neccesary to split giving:
becomes
Except for that, all changes I've observed it making is within "normal" for the codebase. Currently (as of clang format 18) the first problem is unfixable - a PR to fix it had been stuck since 2020, and has since been closed. The second I have not been able to find a solution to.
In the name of not letting the perfect be the enemy of the good, I still propose adopting this. It "fixes" a lot of inconsistent formatting as it is now, and I think it is a nice developer experience to be able to write a piece of code, and have most of the formatting taken care of by a tool.