Back to all reviewers

Use descriptive names

influxdata/influxdb
Based on 8 comments
Go

Names in code should be self-documenting, accurately reflect purpose, and follow consistent conventions. Apply these principles throughout your code:

Naming Conventions Go

Reviewer Prompt

Names in code should be self-documenting, accurately reflect purpose, and follow consistent conventions. Apply these principles throughout your code:

  1. Function/method names must accurately reflect behavior
    // Poor: Name doesn't match behavior (returns true even for running compactions)
    func FullyCompacted() (bool, string)
       
    // Better: Name accurately reflects behavior
    func CompactionOptimizationAvailable() (bool, string)
    
  2. Variable names should describe their content
    // Poor: Name suggests future action, but tracks completed fields
    var fieldsToCreate []*FieldCreate
       
    // Better: Name reflects actual content
    var createdFields []*FieldCreate
    
  3. Use named return values for clarity
    // Poor: Purpose of return values unclear
    func CreateFieldIfNotExists(name string, typ influxql.DataType) (*Field, bool, error)
       
    // Better: Return values purpose is clear
    func CreateFieldIfNotExists(name string, typ influxql.DataType) (f *Field, created bool, err error)
    
  4. Define constants for literal values
    // Poor: Magic strings scattered in code
    if t.HashedToken != "" {
      token = "REDACTED"
    } else {
      variantName = "N/A"
    }
       
    // Better: Named constants with clear semantics
    const (
      TokenRedacted = "REDACTED"
      ValueNotAvailable = "N/A"
    )
    
  5. Function naming should align with behavior
    // Poor: Name implies it starts a goroutine but doesn't
    func startFileLogWatcher(w WatcherInterface, e *Executor, ctx context.Context)
       
    // Better: Name reflects actual function behavior
    func fileLogWatch(w WatcherInterface, e *Executor, ctx context.Context)
    

Clear, descriptive naming reduces cognitive load, improves maintainability, and helps prevent bugs by making code behavior more obvious.

8
Comments Analyzed
Go
Primary Language
Naming Conventions
Category

Source Discussions