-
Notifications
You must be signed in to change notification settings - Fork 444
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
Implement the Google variable naming style more faithfully. #4410
base: main
Are you sure you want to change the base?
Conversation
.clang-tidy
Outdated
- { key: readability-identifier-naming.ClassMemberCase, value: camelCase } | ||
- { key: readability-identifier-naming.ClassMemberSuffix, value: _ } | ||
- { key: readability-identifier-naming.PrivateMemberSuffix, value: _ } | ||
- { key: readability-identifier-naming.ProtectedMemberSuffix, value: _ } |
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.
We tend to use snake_case for private/internal members (including for members that are "logically" private but exposed publicly for logging/debugging). Not sure if clang-tidy provides a way to note that.
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, specific case for private members is possible with https://clang.llvm.org/extra/clang-tidy/checks/readability/identifier-naming.html#cmdoption-arg-PrivateMemberCase
But marking a public member logically private is not.
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.
At least in the compiler front end and libraries, the common style seems to be camelCase
for everything. We can easily change that with an automated clang-tidy
run. But that will assuredly break downstream back ends and repositories.
4970f9f
to
40a1c4d
Compare
Do we want to add |
40a1c4d
to
78a370e
Compare
Sure. |
Unfortunately, there is no way to distinguish between a private and public typedef for now. But we could add the _t suffix. However, the current configuration here uses the prefix style. So This is what it would look like:
For reference, other styles:
C# style is:
|
78a370e
to
a3cd02b
Compare
I don't have many strong opinions about naming style. Personally I find Do you prefer to enforce this (by a CI check)? Did you try how large changes are needed to make the codebase conform? |
We are still missing Clang-tidy support for this (#4254).
There are quite a few changes needed across the codebase, but I'd say we can just gradually fix them. Just having the clang-tidy standards will encourage developers to use the right naming scheme. |
Would the clang-tidy still run very slowly if you disabled all the checks except for the formatting once? Maybe then it would be manageable. Of course, if we wanted enforce it we would also have to re-format whole codebase at once. |
Yes, I have not found a way yet. But even having it as part of CMakelists is already useful for cleanup, e.g., #4326
I do not think this is necessary, we can do this gradually. Unlike clang-format these changes are more sensitive. |
a3cd02b
to
b8d1f1d
Compare
Fixes #4404.
The closest approximation of the Google style I could find is defined here: https://github.com/googleapis/google-cloud-cpp/blob/main/.clang-tidy#L104
We deviate quite a bit. For example, we use
camelCase
in most places instead ofCamelCase
andsnake_case
for variables. I do not have a strong opinion on the style except that we should decide for one and stick to it. These days clang-tidy is advanced enough to actually enforce it, which is nice.Pinging some people on this PR to get agreement. This will be helpful in reviews going forward.