domains / / istio/istio
Use descriptive names
Names should accurately reflect their actual functionality and behavior. Avoid misleading or vague identifiers that don't match what the code actually does.
Names should accurately reflect their actual functionality and behavior. Avoid misleading or vague identifiers that don’t match what the code actually does.
Key principles:
- Accuracy over brevity: Choose names that clearly indicate the actual behavior, even if longer (e.g.,
allowOverwriteinstead ofRotationwhen not doing true rotation) - Be specific about behavior: Use precise terms that distinguish between similar concepts (e.g.,
IsNetworkGatewayinstead ofIsGatewayto differentiate from other gateway types) - Method names should reflect purpose: If a method doesn’t mutate, use names like
WithServiceinstead ofAddService; if it updates cache, name it accordingly rather thanGetPublicKey - Avoid redundant context: Don’t repeat information already available (e.g.,
Key()instead ofGetIstioEndpointKey()when called on an IstioEndpoint) - Use meaningful variables: Replace single-letter variables with descriptive names (e.g.,
clt.Config().Service()instead of"a") - Follow Go conventions: Avoid prefixes like
kin variable names (annotationinstead ofkAnnotation)
Example:
// Poor: misleading name
func (ep *IstioEndpoint) GetIstioEndpointKey() string { ... }
// Better: concise and clear
func (ep *IstioEndpoint) Key() string { ... }
// Poor: doesn't reflect actual behavior
func AddService(service *Service) WasmPluginListenerInfo { ... }
// Better: indicates non-mutating operation
func WithService(service *Service) WasmPluginListenerInfo { ... }