domains / / llvm/llvm-project
Use descriptive semantic names
Choose specific, meaningful names that clearly convey purpose and follow established codebase patterns. Avoid generic terms that could apply to many different concepts.
Choose specific, meaningful names that clearly convey purpose and follow established codebase patterns. Avoid generic terms that could apply to many different concepts.
Key principles:
-
Avoid overloaded generic terms: Instead of generic names like
kind()that “mean sooooo many different things,” use specific descriptive names liketemplateKind()ornameKind()that clearly indicate what type of classification is being provided. -
Follow capitalization conventions: Variable names should start with capital letters where required by the codebase style. For example,
vAddrshould beVirtualAddrfor better readability and consistency. -
Use positive boolean naming: Prefer positive constructions like
EnableMISchedLoadClusteringover negative ones likeDisableMISchedLoadClustering. This creates clearer auto-generated method names likeenableXXX()rather than confusing double negatives. -
Follow established patterns: Synthetic variants should use lowercase suffixes, attribute spellings should match existing conventions, and naming should be consistent with similar constructs in the codebase.
-
Prefer explicit over implicit: Use fully qualified names rather than
usingdeclarations when it improves clarity, especially for types that might be ambiguous in context.
Example:
// Avoid generic, overloaded terms
TemplateNameKind kind() const; // ❌ Generic "kind"
// Use specific, descriptive names
TemplateNameKind templateKind() const; // ✅ Clear purpose
// Follow positive naming for booleans
def TuneDisableMISchedLoadClustering; // ❌ Negative construction
def TuneEnableMISchedLoadClustering; // ✅ Positive, clear methods