Names in code should be self-documenting, accurately reflect purpose, and follow consistent conventions. Apply these principles throughout your code:
Names in code should be self-documenting, accurately reflect purpose, and follow consistent conventions. Apply these principles throughout your code:
// 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)
// Poor: Name suggests future action, but tracks completed fields
var fieldsToCreate []*FieldCreate
// Better: Name reflects actual content
var createdFields []*FieldCreate
// 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)
// 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"
)
// 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.
Enter the URL of a public GitHub repository