doxide icon indicating copy to clipboard operation
doxide copied to clipboard

ADD `.clang-format` for convenience

Open jkhoogland opened this issue 1 year ago • 1 comments

It might be handy to add a .clang-format with your (doxide) preferred formatting style.

When I added something as a PR, I noticed that my global .clang-format file was picked up when saving the modified file in the PR.

jkhoogland avatar Nov 28 '24 19:11 jkhoogland

Yes, good idea @jkhoogland, let me do that in a future iteration.

lawmurray avatar Nov 30 '24 04:11 lawmurray

I can take this issue up to ease development and contribute a .clang-format file: which style do you use/suggest?

Furthermore, how about adding an .editorconfig file? I notice, for example, the top CMakeLists.txt has non-consistent indenting here and here. At least, an .editorconfig file helps keeping contributors aligned. This is not as nearly as detailed as a .clang-format, but supported by many editors and works on virtually file (C++, CMake, Bash, YAML, ...) to ensure a consistent formatting across all files.

alberto-scolari avatar Oct 26 '25 11:10 alberto-scolari

Thanks @alberto-scolari. I have a .clang-format lying around from another project, and I've just added that. It's as close as I can get to my preferred style. I'm not familiar with .editorconfig but happy to accept a PR with that.

Short story:

  • K&R brace style.
  • Indenting with two spaces, no tabs.
  • Wrap at 78 characters (but sometimes rules need to be broken).

I realise there are some inconsistencies in the current codebase. I try not to get too pedantic with new contributors as long as the code is neat. And, as @jkhoogland originally suggested, this file should help with that.

Additional pedantry that, if I recall correctly, I tried to encode in this .clang-format, but is more personal style than essential:

  • When wrapping, I like to indent four spaces but only once, with line breaks after operators, e.g.
    if (something1 && something2 && something3 &&
        something4 && something5 && is_this_true(
        some_var) && something6) {
      // ...
    }
    
  • I like to put spaces around low-precedence operators but not high-precedence operators, as it makes code more readable to me. So you'll see me write a*b + c instead of a*b+c or a * b + c.

But again, this is more personal style, and if it works for contributors then great, but the K&R and indenting with two spaces is the main thing.

lawmurray avatar Oct 29 '25 09:10 lawmurray