Back to all reviewers

Use semantically accurate names

apache/kafka
Based on 9 comments
Java

Choose names that accurately reflect the purpose, scope, and semantics of variables, methods, and classes. Names should be self-documenting and eliminate ambiguity about what the code element represents or does.

Naming Conventions Java

Reviewer Prompt

Choose names that accurately reflect the purpose, scope, and semantics of variables, methods, and classes. Names should be self-documenting and eliminate ambiguity about what the code element represents or does.

Key principles:

  • Match scope to name: If functionality expands beyond the original name, update it accordingly (e.g., updateVoterPeriodTimer โ†’ updateVoterSetPeriodTimer when it handles add, remove, and update operations)
  • Use precise terminology: Avoid vague or ambiguous terms (e.g., isMarkedArchived โ†’ isTerminalState for a boolean indicating no further state transitions)
  • Make purpose explicit: Method names should clearly indicate their function (e.g., getInternalTopics โ†’ getInternalTopicsToBeDeleted when the intent is deletion)
  • Eliminate confusion: When similar concepts exist, use distinguishing names (e.g., boolean isReconfigSupported instead of generic parameter names)

Example improvements:

// Before: Ambiguous about what "messages" vs "records" means
int maxInFlightMessages;
// After: Consistent with codebase terminology  
int maxInFlightRecords;

// Before: Unclear what constitutes "marked archived"
private boolean isMarkedArchived = false;
// After: Clear semantic meaning - no further transitions allowed
private boolean isTerminalState = false;

// Before: Generic parameter name requiring context to understand
public void testMethod(boolean withKip853Rpc)
// After: Self-documenting parameter name
public void testMethod(boolean isReconfigSupported)

Well-chosen names reduce the need for comments and make code intentions immediately clear to readers.

9
Comments Analyzed
Java
Primary Language
Naming Conventions
Category

Source Discussions