geometry icon indicating copy to clipboard operation
geometry copied to clipboard

experimental: use clang-format for buffer and graph

Open barendgehrels opened this issue 8 months ago • 4 comments

Applied on two folders only!

This is experimental and verifies how clang-format could be used for our code base, using a style that is most close to what we (in general) use.

I used clang-format-15.

Other Boost libraries

clang-format is used by a few other boost libraries. I tried some of these configurations, but it was not satisfactory to my taste. Here an indication (on a branch of somewhere last year), with sizes in bytes:

  414  ./graph/.clang-format
  706  ./multiprecision/.clang-format
 1721  ./outcome/.clang-format
 2561  ./histogram/.clang-format
 3111  ./yap/.clang-format
 4108  ./nowide/.clang-format
 5697  ./locale/.clang-format

  685 ./geometry/.clang-format

barendgehrels avatar Apr 26 '25 10:04 barendgehrels

This looks very convenient and I think having a style that can be programmatically enforced but is slightly different from before is better than having a style that is more difficult to ensure consistency for, I'm definitely in favour of this change.

The behaviour for namespaces and empty structs can maybe be made closer to the original by breaking up the Allman style into custom rules to partially address https://github.com/boostorg/geometry/pull/1400#discussion_r2061260800 and https://github.com/boostorg/geometry/pull/1400#discussion_r2061259626 like this:

-BreakBeforeBraces: Allman
+BreakBeforeBraces: Custom
+BraceWrapping:
+  AfterClass: true
+  AfterControlStatement: true
+  AfterEnum: true
+  AfterFunction: true
+  AfterNamespace: false
+  AfterStruct: true
+  AfterUnion: true
+  AfterExternBlock: true
+  BeforeCatch: true
+  BeforeElse: true
+  BeforeLambdaBody: true
+  SplitEmptyFunction: false
+  SplitEmptyRecord: false
+  SplitEmptyNamespace: false
+  IndentBraces: false

The following may also be of interest, if this is to be mass-applied, to somewhat preserve the ability to use git blame to understand why some particular line was changed, it requires logging the commit in a file called .git-blame-ignore-revs at root. https://docs.github.com/en/repositories/working-with-files/using-files/viewing-and-understanding-files#ignore-commits-in-the-blame-view

tinko92 avatar Apr 27 '25 06:04 tinko92

hi @vissarion , I'll not merge it - but just to gauge your opinion, do you like it and the proposed styling?

barendgehrels avatar May 15 '25 17:05 barendgehrels

The following may also be of interest, if this is to be mass-applied, to somewhat preserve the ability to use git blame to understand why some particular line was changed, it requires logging the commit in a file called .git-blame-ignore-revs at root. https://docs.github.com/en/repositories/working-with-files/using-files/viewing-and-understanding-files#ignore-commits-in-the-blame-view

Very interesting, thanks! So we should use that indeed.

barendgehrels avatar May 15 '25 17:05 barendgehrels

hi @vissarion , I'll not merge it - but just to gauge your opinion, do you like it and the proposed styling?

I definitely like it and I am in favor of using clang-format.

vissarion avatar May 16 '25 09:05 vissarion