-
-
Notifications
You must be signed in to change notification settings - Fork 675
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
STYLE: Disable clang-format style option AlignConsecutiveDeclarations
#5096
STYLE: Disable clang-format style option AlignConsecutiveDeclarations
#5096
Conversation
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.
💯
3213446
to
4c96943
Compare
@N-Dekker could you push the changes after applying the new formatting as a second commit? That will facilitate online discussion. |
Sure! Is there an easy way to re-apply clang-format to all ITK C++ files (not the Python files, CMake files, etc., and not the Third Party files)? I locally tried the following "hand-made" command-line in Windows, on Git Bash. It does quite a lot, but it may be incomplete:
Is there a better way? Or should something like this be good enough? |
I think this should do it: pixi run pre-commit-run -a clang-format |
Thanks @hjmjohnson Really cool, if it works like that. Unfortunately I got:
Do you have a clue? |
@N-Dekker YES! That is the desired behavior. The clang-format failed hook failed because the files were changed by clang format. I think that was the desired behavior. You now need to make a commit of the changed files that represent the new clang-format style. |
No longer enabled the style option of aligning consecutive declarations. The convention of aligning declarations has always bothered some of us, as appeared already during the discussion at https://discourse.itk.org/t/update-coding-style-for-itk/2055 (back in 2019). While this style option may be just a matter of taste, it appears to hinder the collaborative development process, as it pollutes [git] blame, it makes changes to lines that aren't really changing, complicating code review, etc., as Sean McBride remarked at InsightSoftwareConsortium#5015 (comment). Moreover, it also triggers unnecessary git merge conflicts. Now that clang-format is recently upgraded for ITK (pull request InsightSoftwareConsortium#5015 commit 0b1fabd), it appears the right moment to reconsider this option.
Did run clang-format on the entire source tree, by: pixi run pre-commit-run -a clang-format As suggested by Hans Johnson.
Thanks @hjmjohnson It works 👍 Unfortunately the commit (modifying 3012 files) takes hours, yes literally hours, saying:
Is there a way to speed up doing such a bulk commit? |
4c96943
to
a89186c
Compare
The |
https://github.com/InsightSoftwareConsortium/ITK/pull/5096/files says:
Indeed: this pull request would change 3014 files 🤷 If I would do it again, I would prefer to exclude "Examples" from this pull request (and make a separate "Examples" pull request). Also because it just takes too much time to for me to do a single But for now, it's ready for review 🎉 |
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.
Splitting the change into Examples and rest of the toolkit also sounds fine. But good as-is.
Thanks @dzenanz If this PR can get merged "as-is", it's also fine by me. But if it would need to be amended, or if it would get merge conflicts, I'll consider splitting the change into Examples and the rest as well. |
As we would like consensus on this matter, it is advisable to leave it open for longer to give more chance to all maintainers to pitch in. This will almost certainly lead to conflicts when it comes merge time (just preparing you psychologically 😄). |
Wow! I did this on my SSD drive mac laptop, and applying the changes from the updated .clang-format only took a few seconds. Seems like perhaps there is something going on beyond just the running of clang-format. |
I do not think this should be changed. It adds a very large readability value. While it may occasionally add some merge conflicts, I do not think that justifies the trade-off. This was the style of ITK before clang-format. With pre-commit clang-format, the spaces are automatically added as-needed, so it is not a burden on the author. |
I just tried it on my computer, and it took 17 seconds. So it is not Windows-specific, it might be specific to your computer Niels. |
These are my thoughts on this:
So I'd vote for keeping the alignment to |
Thanks very much for your elaborate feedback, @jhlegarreta Just a clarification (or correction?) regarding your last two bullets:
I would like to clarify: when disabling Please let us know if this clarification might make you reconsider your vote 😺 |
|
||
auto image = VariableLengthVectorImageType::New(); | ||
auto image = VariableLengthVectorImageType::New(); | ||
VariableLengthVectorImageType::IndexType start; | ||
InternalPixelType f(VectorLength); | ||
VariableLengthVectorImageType::SizeType size; | ||
InternalPixelType f(VectorLength); | ||
VariableLengthVectorImageType::SizeType size; |
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.
@thewtex Thanks for your feedback! It's obviously a matter of taste, but I find this proposed change an improvement of the readability. Old code (having enabled declaration alignment):
auto image = VariableLengthVectorImageType::New();
VariableLengthVectorImageType::IndexType start;
InternalPixelType f(VectorLength);
Proposed with this pull request:
auto image = VariableLengthVectorImageType::New();
VariableLengthVectorImageType::IndexType start;
InternalPixelType f(VectorLength);
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.
Yes, when there are fewer items, it is more of a preference. This example, with fewer items and highly varying type lengths, is more compact. In general, it is easier to read when they are aligned.
More significantly, when there are many items, it is much easier to identify the types and values when visually aligned.
@N-Dekker better performance may come from Git Bash (the default with Git for Windows) or the Windows Subsystem for Linux (WSL). |
That command was fast both in |
👍 Thanks.
No changes. |
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'm conflicted, my personal (developer) preference is to minimize
git conflicts as much as possible. I "want" this PR for personal
reasons.
However, the ghost of christmas past "aka Bill Lorensen," kept bothering me
during my review of this PR. The reminder was that core ITK developers 'should carry
the extra burden of making end-users or novice users use easier'. Then Luis Ibanez
haunted me to remind me that lesson from "Clean Code" that
'code is read much more than it is written'
I'm converging on the conclusion that my personal preference
is probably not what is best for the community.
I think that when large blocks of code are changed due to this formatting
the decision, that it is often an indication of missing whitespace between blocks
of unrelated variables, or that the variables are declared in a block without
enforcing the principle that variables should be declared in locally to where
they are needed, and in the smallest scope possible.
This is clearly my opinion, but I wanted to give a longer
explanation of my current position.
Thanks for your elaborate reply, Hans. Honestly it's a bit overwelming to me. Code readability is and has always been one of my main priorities. As well as readability of documentation, commit messages, etc. I hope you don't think otherwise about me! It's my impression that alignment of declarations sometimes increases readability, and in other cases decreases readability. However, it's partially just a matter of taste. 🤷 A commit like 5b5e4b2 (June 9, 2014) supports your claim that Bill would prefer alignment of consecutive declarations. And apparently, also Luis (@luisibanez) prefers such alignments, looking at "itkTestingExtractSliceImageFilterTest.cxx" commit cba75da (April 13, 2014). However, I don't think that removing such alignments would be against the spirit of ITK. We made many other coding style changes over the years. This would just be one of them. For the record: The default LLVM style (that you get by However, given the current resistance against this pull request I feel that I have to stop my effort now to get it merged. Of course, it's a bit disappointing to me. But then again, I already had my fair share of merged pull requests on ITK, for 2024 😃 |
No longer enabled the style option of aligning consecutive declarations.
The convention of aligning declarations has always bothered some of us, as appeared already during the discussion at https://discourse.itk.org/t/update-coding-style-for-itk/2055 (back in 2019).
While this style option may be just a matter of taste, it appears to hinder the collaborative development process, as it pollutes [git] blame, it makes changes to lines that aren't really changing, complicating code review, etc., as Sean McBride (@seanm) remarked at #5015 (comment). Moreover, it also triggers unnecessary git merge conflicts.
Now that clang-format is recently upgraded for ITK (pull request #5015 commit 0b1fabd), it appears the right moment to reconsider this option.