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 → isRegexParseDomainsAndRegex → ParseHostMatchersCustomResponseWriter → StatusRecorderFailTimeout → FailureWindow (time window vs timeout duration)MaxFails → MaxFailedAttemptsdown → up when variable represents “up” statusdefaultCacheDuration instead of cache.DefaultExpirationExample:
// 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