Canonical guidance

Use when

Avoid

Preferred pattern

func filter(xs []int) []int {
	var out []int
	for _, x := range xs {
		if x%2 == 0 {
			out = append(out, x)
		}
	}
	return out
}

Anti-pattern

Explanation: This anti-pattern is tempting because empty slices feel tidier, but unnecessary normalization adds noise and hides which boundary actually cares.

Why

Related pages

Sources