domains / observability / SigNoz/signoz
consistent descriptive naming
Use meaningful, descriptive names that clearly convey purpose and maintain consistency across similar concepts throughout the codebase. Avoid magic strings, cryptic abbreviations, and inconsistent naming patterns.
Use meaningful, descriptive names that clearly convey purpose and maintain consistency across similar concepts throughout the codebase. Avoid magic strings, cryptic abbreviations, and inconsistent naming patterns.
Key principles:
- Replace magic strings with constants: Instead of
"clickhouse_max_threads", createconst ClickhouseMaxThreadsKey = "clickhouse_max_threads" - Use consistent naming patterns: If using “legacy/current” convention in one place, apply it consistently elsewhere (e.g.,
serverAddrLegacyIdxandserverAddrCurrentIdxinstead of mixingserverAddrIdxandnetPeerIdx) - Choose descriptive variable names: Replace cryptic names like
k, mwith meaningful ones likemetricName, isNormalized - Use semantic function names:
GetTransitionedMetric(singular) instead ofGetTransitionedMetricswhen operating on single items - Follow established conventions: Use
NewNotFoundfinstead ofNotFoundNewfor natural readability, andStart/Endinstead ofStartDate/EndDatefor timestamp fields - Maintain naming consistency across similar concepts: Use
alert_idconsistently if other IDs follow underscore convention
Example of good naming consistency:
const (
ServerNameLegacyKey = "net.peer.name"
ServerNameCurrentKey = "server.address"
URLPathLegacyKey = "http.url"
URLPathCurrentKey = "url.full"
)
// Consistent variable naming
serverAddrLegacyIdx := -1
serverAddrCurrentIdx := -1
This approach improves code readability, reduces confusion during reviews, and makes the codebase more maintainable by establishing clear naming patterns that developers can follow consistently.