Choose names that clearly communicate their purpose and avoid ambiguity or misinterpretation. Names should be self-documenting and consider what developers will wonder about at the call site.
Key principles:
isExecutableNonTestRule
instead of isExecutableRule
when the distinction matters to callersunderlying
with more precise terms like hidden
or server
when the context is unclearUNKNOWN_CPU_TIME
over generic UNKNOWN
when the context mattersapplyInvalidation
accurately reflect what the method does rather than how it might be interpretedExample:
// Ambiguous - what kind of rule?
public static boolean isExecutableRule(Target target)
// Clear - specifies it excludes test rules
public static boolean isExecutableNonTestRule(Target target)
// Vague constant
private static final long UNKNOWN = -1;
// Descriptive constant
private static final long UNKNOWN_CPU_TIME = -1;
This approach reduces cognitive load, prevents misunderstandings, and makes code more maintainable by ensuring names serve as clear documentation of intent.
Enter the URL of a public GitHub repository