Adopt naming conventions for constant fields#5554
Conversation
* public, protected and package-private constants must be upper case * private constants may have any case * except for logger which must be lowercase.
95a69c9 to
e4961fd
Compare
This comment has been minimized.
This comment has been minimized.
|
Making loggers lowercase sounds reasonable to me. The rationale I've seen elsewhere for making loggers lowercase is that they're not really constants so much as side-effecting "do-ers" that just so happen to be On the other hand, uppercase naming for I haven't searched the code for any of the other |
|
From Joshua Blogs, Effective Java v2, p238
The mutability is important here and I think we can consider loggers to be mutable. They're holding a reference to the logging system which hold state somewhere. And combined with the advice to minimize accessibility and mutability for public parts of the API, I think we could adopt the convention that |
✅ All tests passed ✅🏷️ Commit: 956b129 Learn more about TestLens at testlens.app. |
A constant field is a
static finalfield whose value is immutable. If a static final field has a primitive type or an immutable reference type it is a constant field. Constants should be named with uppercase words separated by underscores. Non-constantstatic finalfields should be named with camel case.For example a
public static final String KEYis immutable and a constant, whileprivate static final Logger loggerholds a reference to the logging system, is mutable and not a constant.While I've not checked all occurrences, we generally follow this convention in production code. However when discussing #5424 we noticed a drift towards
LOGGER. Specifically:logger.LOGGER.To ensure this drift doesn't persist:
Out of scope: enforce that non-private static final fields are actually constants.
I hereby agree to the terms of the JUnit Contributor License Agreement.
Definition of Done
@APIannotations