In #11777, the readonly modifier was added to internal static members which raised an issue of our naming convention.
According to StyleCopAnalyzers on CodeFactor, "readonly variables that are not declared private must start with an upper-case letter" otherwise there are violations of the rule SA1304NonPrivateReadonlyFieldsMustBeginWithUpperCaseLetter
Our naming conventions state static fields should start with s_, however the existing code overwhelmingly uses PascalCase for internal static readonly members.
In my view conventions should be descriptive rather than prescriptive, so we should consider making changes to the written naming convention.
Yeah most of the newer code I see uses PascalCase for these. Might be that our naming conventions doc needs an update? /cc @SteveL-MSFT
https://github.com/dotnet/codeformatter/issues/281#issuecomment-442733951 makes a case that readonly should not change the casing style or prefixes.
I don't have a strong opinion either way, but CodeFactor rules should not conflict with naming conventions – it adds too much friction to pull requests.
Currently, the PowerShell naming convention states:
Use
_camelCaseto name internal and private fields and usereadonlywhere possible.
Prefix instance fields with_, static fields withs_and thread static fields witht_.
Unfortunately there is no StyleCop rule available to enforce the use of _camelCase for internal.
I think the following changes would be reasonably descriptive of the existing codebase:
_camelCase to name private fields (and prefix instance fields with _, static fields with s_ and thread static fields with t_).PascalCase to name non-private fields.If we modified the written convention as suggested we could enforce this using the StyleCop rule:
SA1307: AccessibleFieldsMustBeginWithUpperCaseLetter.
We should also consider: https://github.com/dotnet/runtime/blob/master/docs/coding-guidelines/coding-style.md
GitHub
.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps. - dotnet/runtime
/cc @adityapatwardhan @daxian-dbw @TravisEz13 Thoughts?
If we want to modify our code style, we should modify our code style doc. We can discuss it there. I would suggest one issue at a time and not changing any existing rule without a good reason. the main reason for them is internal consistency. cc @daxian-dbw
Most helpful comment
https://github.com/dotnet/codeformatter/issues/281#issuecomment-442733951 makes a case that
readonlyshould not change the casing style or prefixes.I don't have a strong opinion either way, but CodeFactor rules should not conflict with naming conventions – it adds too much friction to pull requests.