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:
"clickhouse_max_threads", create const ClickhouseMaxThreadsKey = "clickhouse_max_threads"serverAddrLegacyIdx and serverAddrCurrentIdx instead of mixing serverAddrIdx and netPeerIdx)k, m with meaningful ones like metricName, isNormalizedGetTransitionedMetric (singular) instead of GetTransitionedMetrics when operating on single itemsNewNotFoundf instead of NotFoundNew for natural readability, and Start/End instead of StartDate/EndDate for timestamp fieldsalert_id consistently if other IDs follow underscore conventionExample 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.
Enter the URL of a public GitHub repository