Prompt
Names in code should be self-documenting, accurately reflect purpose, and follow consistent conventions. Apply these principles throughout your code:
- 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) - 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 - 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) - 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" ) - 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.