Canonical guidance

Use when

Avoid

Preferred pattern

f, err := os.Open(name)
if err != nil {
	return err
}
defer f.Close()

Anti-pattern

Explanation: This is tempting during refactors, but same-block short declarations have a strict rule and fail when no new non-blank identifier is introduced.

Why

Related pages

Sources