-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add explanation of underscore-separated units in variable names [ci skip] #6470
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
✅ All tests successful. No failed tests found. Additional details and impacted files@@ Coverage Diff @@
## dev-2.x #6470 +/- ##
=============================================
+ Coverage 70.10% 70.24% +0.13%
- Complexity 18209 18368 +159
=============================================
Files 2073 2087 +14
Lines 77318 77381 +63
Branches 7820 7839 +19
=============================================
+ Hits 54205 54356 +151
+ Misses 20344 20250 -94
- Partials 2769 2775 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Perhaps a more fitting place would be NamingConventions.md.
Yes, I considered that too. There was no section there on variables, but I could add one. |
|
||
## Variables | ||
|
||
We follow the Java standard of using camelCase with a lower-case first letter for variable names. However, variables of numeric types may include units as an underscore-separated suffix. For example, `length_mm` or `duration_msec`. The reason is that case is significant in metric prefixes (e.g. `M` for mega- versus `m` for milli-). The underscore also reinforces that these are units rather than part of the base variable name. |
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.
Idk if we should mention about the "edge case" of static fields where we also use underscore.
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.
Are you thinking of constants (static final int SOME_CONSTANT
)? I'll reword it slightly to reference the Java Style Guide so all these cases are covered by reference.
Co-authored-by: Thomas Gran <[email protected]>
Thank you for doing this @abyrd, I will merge it now. |
As discussed in a recent meeting, this adds a short explanation of why some variables have underscore-separated units as part of their names, defying standard camelCase.
It seems a little strange to update an already existing decision record, but this is a very minor point and probably less likely to be seen if it were split out into a separate style document.