Prefer defaulting and naked switches over if/else chains for shallow branching logic in Go. Use when writing or refactoring conditional logic with 1-3 branches.
73
90%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Passed
No findings from the security scan
For shallow branching (1-3 cases), prefer defaulting or naked switches over if/else chains. This reduces nesting, avoids duplication, and lowers the cognitive load.
any / map[string]anyInitialize the variable with its default value, then override only in the special case.
❌ Avoid:
var result map[string]any
if outer, ok := input["outer"].(map[string]any); ok {
if inner, ok := outer["inner"].(map[string]any); ok {
result = make(map[string]any, len(inner))
maps.Copy(result, inner)
} else {
result = make(map[string]any)
}
} else {
result = make(map[string]any)
}✅ Prefer:
result := make(map[string]any)
if outer, ok := input["outer"].(map[string]any); ok {
if inner, ok := outer["inner"].(map[string]any); ok {
result = make(map[string]any, len(inner))
maps.Copy(result, inner)
}
}❌ Avoid:
if a > b {
result = a
} else if a == b {
result = a + b
} else {
result = b
}✅ Prefer:
switch {
case a > b:
result = a
case a == b:
result = a + b
default:
result = b
}For simple two-way numeric comparisons, prefer the min/max built-ins (Go 1.21+):
result := max(a, b)maps.Copy(dst, src) instead of manual copy loops (destination must be non-nil)cmp.Or(a, b, "default") to pick the first non-zero value across fallbacksv, ok := x.(T) for type assertions7c54ee3
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.