mirror of
https://github.com/teivah/100-go-mistakes.git
synced 2026-06-21 17:07:18 +08:00
Add ToC
This commit is contained in:
parent
2a0df76eb6
commit
35a1a5f440
1 changed files with 101 additions and 0 deletions
101
README.md
101
README.md
|
|
@ -24,16 +24,117 @@ _Want your company name to appear here? Go to [❤️ Sponsor](https://github.co
|
|||
This section contains a summary of the 100 mistakes in the book. Meanwhile, it's also a section open to the community. If you believe that a mistake should be added, please create a [community mistake issue](https://github.com/teivah/100-go-mistakes/issues/new?assignees=&labels=community+mistake&template=community_mistake.md&title=).
|
||||
|
||||
* [Code and Project Organization](#code-and-project-organization)
|
||||
* [Unintended variable shadowing](#unintended-variable-shadowing-1)
|
||||
* [Unnecessary nested code](#unnecessary-nested-code-2)
|
||||
* [Misusing init functions](#misusing-init-functions-3)
|
||||
* [Overusing getters and setters](#overusing-getters-and-setters-4)
|
||||
* [Interface pollution](#interface-pollution-5)
|
||||
* [Interface on the producer side](#interface-on-the-producer-side-6)
|
||||
* [Returning interfaces](#returning-interfaces-7)
|
||||
* [`any` says nothing](#any-says-nothing-8)
|
||||
* [Being confused about when to use generics](#being-confused-about-when-to-use-genericshttpsteivahmediumcomwhen-to-use-generics-in-go-36d49c1aeda-9) ([Read the full excerpt 👀](https://teivah.medium.com/when-to-use-generics-in-go-36d49c1aeda))
|
||||
* [Not being aware of the possible problems with type embedding](#not-being-aware-of-the-possible-problems-with-type-embedding-10)
|
||||
* [Not using the functional options pattern](#not-using-the-functional-options-pattern-11)
|
||||
* [Project misorganization](#project-misorganization-project-structure-and-package-organization-12)
|
||||
* [Creating utility packages](#creating-utility-packages-13)
|
||||
* [Ignoring package name collisions](#ignoring-package-name-collisions-14)
|
||||
* [Missing code documentation](#missing-code-documentation-15)
|
||||
* [Not using linters](#not-using-linters-16)
|
||||
* [Data Types](#data-types)
|
||||
* [Creating confusion with octal literals](#creating-confusion-with-octal-literals-17)
|
||||
* [Neglecting integer overflows](#neglecting-integer-overflows-18)
|
||||
* [Not understanding floating-points](#not-understanding-floating-points-19)
|
||||
* [Not understanding slice length and capacity](#not-understanding-slice-length-and-capacityhttpsteivahmediumcomslice-length-vs-capacity-in-go-af71a754b7d8-20) ([Read the full excerpt 👀](https://teivah.medium.com/slice-length-vs-capacity-in-go-af71a754b7d8))
|
||||
* [Inefficient slice initialization](#inefficient-slice-initialization-21)
|
||||
* [Being confused about nil vs. empty slice](#being-confused-about-nil-vs-empty-slice-22)
|
||||
* [Not properly checking if a slice is empty](#not-properly-checking-if-a-slice-is-empty-23)
|
||||
* [Not making slice copies correctly](#not-making-slice-copies-correctly-24)
|
||||
* [Unexpected side effects using slice append](#unexpected-side-effects-using-slice-append-25)
|
||||
* [Slice and memory leaks](#slice-and-memory-leaks-26)
|
||||
* [Inefficient map initialization](#inefficient-map-initialization-27)
|
||||
* [Map and memory leaks](#map-and-memory-leakshttpsteivahmediumcommaps-and-memory-leaks-in-go-a85ebe6e7e69-28) ([Read the full excerpt 👀](https://teivah.medium.com/maps-and-memory-leaks-in-go-a85ebe6e7e69))
|
||||
* [Comparing values incorrectly](#comparing-values-incorrectly-29)
|
||||
* [Control Structures](#control-structures)
|
||||
* [Ignoring that elements are copied in `range` loops](#ignoring-that-elements-are-copied-in-range-loops-30)
|
||||
* [Ignoring how arguments are evaluated in `range` loops](#ignoring-how-arguments-are-evaluated-in-range-loops-channels-and-arrays-31)
|
||||
* [Ignoring the impacts of using pointer elements in `range` loops](#ignoring-the-impacts-of-using-pointer-elements-in-range-loops-32)
|
||||
* [Making wrong assumptions during map iterations](#making-wrong-assumptions-during-map-iterations-ordering-and-map-insert-during-iteration-33)
|
||||
* [Ignoring how the `break` statement works](#ignoring-how-the-break-statement-works-34)
|
||||
* [Using defer inside a loop](#using-defer-inside-a-loop-35)
|
||||
* [Strings](#strings)
|
||||
* [Not understanding the concept of rune](#not-understanding-the-concept-of-rune-36)
|
||||
* [Inaccurate string iteration](#inaccurate-string-iteration-37)
|
||||
* [Misusing trim functions](#misusing-trim-functions-38)
|
||||
* [Under-optimized strings concatenation](#under-optimized-strings-concatenation-39)
|
||||
* [Useless string conversions](#useless-string-conversions-40)
|
||||
* [Substring and memory leaks](#substring-and-memory-leaks-41)
|
||||
* [Functions and Methods](#functions-and-methods)
|
||||
* [Not knowing which type of receiver to use](#not-knowing-which-type-of-receiver-to-use-42)
|
||||
* [Never using named result parameters](#never-using-named-result-parameters-43)
|
||||
* [Unintended side effects with named result parameters](#unintended-side-effects-with-named-result-parameters-44)
|
||||
* [Returning a nil receiver](#returning-a-nil-receiver-45)
|
||||
* [Using a filename as a function input](#using-a-filename-as-a-function-input-46)
|
||||
* [Ignoring how `defer` arguments and receivers are evaluated](#ignoring-how-defer-arguments-and-receivers-are-evaluated-argument-evaluation-pointer-and-value-receivers-47)
|
||||
* [Error Management](#error-management)
|
||||
* [Panicking](#panicking-48)
|
||||
* [Ignoring when to wrap an error](#ignoring-when-to-wrap-an-error-49)
|
||||
* [Comparing an error type inaccurately](#comparing-an-error-type-inaccurately-50)
|
||||
* [Comparing an error value inaccurately](#comparing-an-error-value-inaccurately-51)
|
||||
* [Handling an error twice](#handling-an-error-twice-52)
|
||||
* [Not handling an error](#not-handling-an-error-53)
|
||||
* [Not handling `defer` errors](#not-handling-defer-errors-54)
|
||||
* [Concurrency: Foundations](#concurrency-foundations)
|
||||
* [Mixing up concurrency and parallelism](#mixing-up-concurrency-and-parallelism-55)
|
||||
* [Thinking concurrency is always faster](#thinking-concurrency-is-always-fasterhttpsteivahmediumcomconcurrency-isnt-always-faster-in-go-de325168907c-56)
|
||||
* [Thinking concurrency is always faster](#thinking-concurrency-is-always-fasterhttpsteivahmediumcomconcurrency-isnt-always-faster-in-go-de325168907c-56) ([Read the full excerpt 👀](https://teivah.medium.com/concurrency-isnt-always-faster-in-go-de325168907c))
|
||||
* [Being puzzled about when to use channels or mutexes](#being-puzzled-about-when-to-use-channels-or-mutexes-57)
|
||||
* [Not understanding race problems](#not-understanding-race-problems-data-races-vs-race-conditions-and-the-go-memory-model-58)
|
||||
* [Not understanding the concurrency impacts of a workload type](#not-understanding-the-concurrency-impacts-of-a-workload-type-59)
|
||||
* [Misunderstanding Go contexts](#misunderstanding-go-contexts-60)
|
||||
* [Concurrency: Practice](#concurrency-practice)
|
||||
* [Propagating an inappropriate context](#propagating-an-inappropriate-context-61)
|
||||
* [Starting a goroutine without knowing when to stop it](#starting-a-goroutine-without-knowing-when-to-stop-it-62)
|
||||
* [Not being careful with goroutines and loop variables](#not-being-careful-with-goroutines-and-loop-variables-63)
|
||||
* [Expecting a deterministic behavior using select and channels](#expecting-a-deterministic-behavior-using-select-and-channels-64)
|
||||
* [Not using notification channels](#not-using-notification-channels-65)
|
||||
* [Not using nil channels](#not-using-nil-channels-66)
|
||||
* [Being puzzled about channel size](#being-puzzled-about-channel-size-67)
|
||||
* [Forgetting about possible side effects with string formatting](#forgetting-about-possible-side-effects-with-string-formatting-etcd-data-race-example-and-deadlock-68)
|
||||
* [Creating data races with append](#creating-data-races-with-append-69)
|
||||
* [Using mutexes inaccurately with slices and maps](#using-mutexes-inaccurately-with-slices-and-maps-70)
|
||||
* [Misusing `sync.WaitGroup`](#misusing-syncwaitgroup-71)
|
||||
* [Forgetting about `sync.Cond`](#forgetting-about-synccond-72)
|
||||
* [Not using `errgroup`](#not-using-errgroup-73)
|
||||
* [Copying a `sync` type](#not-using-errgroup-74)
|
||||
* [Standard Library](#standard-library)
|
||||
* [Providing a wrong time duration](#providing-a-wrong-time-duration-75)
|
||||
* [`time.After` and memory leaks](#timeafter-and-memory-leaks-76)
|
||||
* [JSON handling common mistakes](#json-handling-common-mistakes-77)
|
||||
* [Common SQL mistakes](#common-sql-mistakes-78)
|
||||
* [Not closing transient resources](#not-closing-transient-resources-http-body-sqlrows-and-osfile-79)
|
||||
* [Forgetting the return statement after replying to an HTTP request](#forgetting-the-return-statement-after-replying-to-an-http-request-80)
|
||||
* [Using the default HTTP client and server](#using-the-default-http-client-and-server-81)
|
||||
* [Testing](#testing)
|
||||
* [Not categorizing tests](#not-categorizing-tests-build-tags-environment-variables-and-short-mode-82)
|
||||
* [Not enabling the race flag](#not-enabling-the-race-flag-83)
|
||||
* [Not using test execution modes](#not-using-test-execution-modes-parallel-and-shuffle-84)
|
||||
* [Not using table-driven tests](#not-using-table-driven-tests-85)
|
||||
* [Sleeping in unit tests](#sleeping-in-unit-tests-86)
|
||||
* [Not dealing with the time API efficiently](#not-dealing-with-the-time-api-efficiently-87)
|
||||
* [Not using testing utility packages](#not-using-testing-utility-packages-httptest-and-iotest-88)
|
||||
* [Writing inaccurate benchmarks](#writing-inaccurate-benchmarkshttpsteivahmediumcomhow-to-write-accurate-benchmarks-in-go-4266d7dd1a95-89) ([Read the full excerpt 👀](https://teivah.medium.com/how-to-write-accurate-benchmarks-in-go-4266d7dd1a95))
|
||||
* [Not exploring all the Go testing features](#not-exploring-all-the-go-testing-features-90)
|
||||
* [Optimizations](#optimizations)
|
||||
* [Not understanding CPU caches](#not-understanding-cpu-caches-91)
|
||||
* [Writing concurrent code that leads to false sharing](#writing-concurrent-code-that-leads-to-false-sharing-92)
|
||||
* [Not taking into account instruction-level parallelism](#not-taking-into-account-instruction-level-parallelism-93)
|
||||
* [Not being aware of data alignment](#not-being-aware-of-data-alignment-94)
|
||||
* [Not understanding stack vs. heap](#not-understanding-stack-vs-heap-95)
|
||||
* [Not knowing how to reduce allocations](#not-knowing-how-to-reduce-allocations-api-change-compiler-optimizations-and-syncpool-96)
|
||||
* [Not relying on inlining](#not-relying-on-inlining-97)
|
||||
* [Not using Go diagnostics tooling](#not-using-go-diagnostics-tooling-profiling-enabling-pprof-cpu-heap-goroutines-block-and-mutex-profiling-and-execution-tracer-98)
|
||||
* [Not understanding how the GC works](#not-understanding-how-the-gc-works-99)
|
||||
* [Not understanding the impacts of running Go in Docker and Kubernetes](#not-understanding-the-impacts-of-running-go-in-docker-and-kubernetes-100)
|
||||
|
||||
### Code and Project Organization
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue