Choose names that clearly express the purpose, behavior, or semantic meaning of variables, functions, and types. Avoid ambiguous or generic names that require additional context to understand their role.
Choose names that clearly express the purpose, behavior, or semantic meaning of variables, functions, and types. Avoid ambiguous or generic names that require additional context to understand their role.
Key principles:
regex
→ isRegex
ParseDomainsAndRegex
→ ParseHostMatchers
CustomResponseWriter
→ StatusRecorder
FailTimeout
→ FailureWindow
(time window vs timeout duration)MaxFails
→ MaxFailedAttempts
down
→ up
when variable represents “up” statusdefaultCacheDuration
instead of cache.DefaultExpiration
Example:
// Ambiguous - what kind of timeout?
type PassiveHealthCheck struct {
FailTimeout ptypes.Duration
MaxFails int
}
// Clear - describes the time window and explicit count
type PassiveHealthCheck struct {
FailureWindow ptypes.Duration
MaxFailedAttempts int
}
This approach reduces cognitive load, prevents misunderstandings, and makes code self-documenting.
Enter the URL of a public GitHub repository