Go (Golang) is designed to be simple, fast, and readable, but even experienced programmers fall into recurring mistakes that harm correctness, performance, readability, or maintainability. The following editorial highlights 100 common Go mistakes, grouped by theme, with concise explanations, examples of the bad pattern, and concrete fixes. Use this as a checklist when writing, reviewing, or refactoring Go code.
Using ioutil (deprecated) functions in new code.
Fix: use io and os package functions per newer Go versions.
By internalizing these mistakes, you will move from "writing Go code that compiles" to "writing Go code that is robust and performant."
// Bad practice
var mu sync.Mutex
go func()
mu.Lock()
// code
mu.Unlock()
()
10. Misunderstanding Type Assertions
Mistake: Using value.(Type) without the comma-ok idiom, causing a panic if the assertion fails.
Avoidance: Always use v, ok := value.(Type).
Focuses on efficiency: Explains why certain data structures or patterns are slower in Go.
- You can buy the eBook (PDF/EPUB) directly from the publisher. They often have deals like "Deal of the Day."
- Website:
manning.com/books/100-go-mistakes-and-how-to-avoid-them