Write code so intent is immediately obvious: avoid repeated boilerplate, collapse near-identical branches, and centralize shared logic/values.
Practical rules:
Example (boolean readability + dedupe):
// Instead of one dense conditional, name the pieces.
websocketTunnel := utilfeature.DefaultFeatureGate.Enabled(features.ExtendWebSocketsToKubelet) &&
wsstream.IsWebSocketRequestWithTunnelingProtocol(request.Request)
if websocketTunnel {
servermetrics.IncStreamingWebSocketRequest("portforward")
// ...
}
Example (test/body dedupe):
topologyPolicyTest := func(topoPolicy string, /* other args */) {
// common test setup and assertions here
}
// Use it for each policy instead of copying the full test body.
topologyPolicyTest("none", ...)
topologyPolicyTest("best-effort", ...)