100 Go Mistakes (2022)

  • Unintended variable shadowing
  • Ignoring logging side effects
  • Comparing values incorrectly
  • JSON handling mistakes
  • Formatting network addresses for IPv4 solely
  • Handling enums incorrectly
  • Not using defer
  • Ignoring how defer arguments and receivers are evaluated
  • Not closing resources
  • Creating confusion with octal literals
  • Neglecting integer overflows
  • Not understanding floating-points
  • Not using linters
  • Writing nested code
  • Misusing init functions
  • Always using getters and setters
  • Interface pollution
  • Interface on producer-side
  • Returning interfaces
  • interface{} says nothing
  • Not using the functional options pattern
  • Project misorganization
  • Creating utility packages
  • Ignoring package name collisions
  • Missing code documentation
  • Not understanding slice length and capacity
  • Inaccurate slice initialization
  • Creating conflicts using slice append
  • Not making slice copy correctly
  • Slice and memory leaks
  • Being confused about nil vs. empty slice
  • Not properly checking if a slice is empty
  • Inaccurate map initialization
  • Ignoring that elements are copied in range loops
  • Ignoring how arguments are evaluated in range loops
  • Ignoring the impacts of using element pointers in range loops
  • Making wrong assumptions during map iterations
  • Ignoring how the break statement work
  • Using defer inside a loop
  • Forgetting about the switch fall through behavior
  • Not understanding the concept of rune
  • Inaccurate string iteration
  • Misusing trim functions
  • Under-optimized strings concatenation
  • Useless string conversion
  • Substring and memory leaks
  • Not knowing which type of receiver to use
  • Not using named result parameters
  • Unintended side-effects with named result parameters
  • Returning a nil receiver
  • Using a filename as a function input
  • Panicking
  • Ignoring when to wrap an error
  • Comparing an error type inefficiently
  • Comparing an error value inefficiently
  • Handling an error twice
  • Ignoring an error
  • Not handling defer errors
  • Mixing concurrency and parallelism
  • Concurrency isn’t always faster
  • Misunderstanding Go contexts
  • Not understanding what a race condition is
  • Append is not always race free
  • Goroutines and loop variables
  • Channel receive/send and context
  • Not using directional channels
  • Not using notification channels
  • Closing channels inaccurately
  • Buffered channel capacity and magic number
  • Not using nil channels
  • Passing a struct containing a sync field
  • Exporting concurrency primitives
  • Not using sync.RWMutex
  • Misusing sync.WaitGroup
  • Forgetting about sync.Cond
  • Not using errgroup package
  • Not using runtime.NumCPU()
  • time.After and memory leak
  • Ignoring false sharing
  • Forgetting to fail a test
  • Not using table-driven tests
  • Not using test build flags
  • Not using the race option
  • Not checking goroutines leaks
  • Writing inaccurate benchmarks
  • Byte slice and map key
  • Pointers everywhere
  • Expecting that a pointer address is constant
  • Structure alignment
  • Inlining
  • Using the default http client and server
  • Go and Docker
  • Not exposing a pprof endpoint
  • Generating random numbers in security-sensitive applications
Follow me on Twitter @teivah

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Teiva Harsanyi

Teiva Harsanyi

Software Engineer @Docker 🐳 | 📖 100 Go Mistakes author | 改善