Skip to content
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

Use ClangFormat for code style #236

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

davidstrauss
Copy link

@davidstrauss davidstrauss commented Mar 10, 2017

Right now, the APCu code has a mix of tabs/spaces and other style inconsistencies. The best tool for rigorous maintenance of code style seems to be ClangFormat, which is also used by the Datastax's Apache Cassandra extension for PHP.

I started with their style and made a few tweaks:

  • SortIncludes: false is necessary to maintain #include "php.h" before lines like #include "main/php_streams.h". Otherwise, the build breaks. It's also possible to solve this with /* clang-format off */ blocks or not grouping the includes that must have explicit ordering, but that can always happen later.
  • Other options like UseTab: never and TabWidth: 4 to harmonize the ClangFormat configuration with the VIM one included in files.
  • Dropping some options that are either defaults for LLVM style or not applicable to APCu.
  • A couple other subjective things.

I don't have strong opinions on any parts of the style (not even spaces vs. tabs!). I'm more interested in having a rigid format than which decisions actually get made. So, I'm happy to reroll with different options.

ClangFormat, unfortunately, has limited options around #if block indentation and macro-heavy code. I don't have strong opinions around this, either.

Some options are:

  • Just accept how ClangFormat removes some indentation around such "blocks."
  • Apply /* clang-format off */ to regions of code heavily dependent on such formatting. I did this for the apcu_functions block, which had rather strange formatting from ClangFormat.
  • Exclude the files with the most reliance on manual formatting, like apc_arginfo.h.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant