Skip to content

Commit

Permalink
Merge pull request #54 from rustinwelter/fix-typo
Browse files Browse the repository at this point in the history
Fix typo
  • Loading branch information
teivah authored Oct 14, 2023
2 parents ba24999 + 44b82de commit c3d7346
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ The last option, `[]string{}`, should be avoided if we initialize the slice with

To check if a slice doesn’t contain any element, check its length. This check works regardless of whether the slice is `nil` or empty. The same goes for maps. To design unambiguous APIs, you shouldn’t distinguish between nil and empty slices.

To determine whether a slice has elements, we can either do it by checking if the slice is nil or if its length is equal to 0. Checking the length is the best option to follow as it will cover both if the slice is empty or is the slice is nil.
To determine whether a slice has elements, we can either do it by checking if the slice is nil or if its length is equal to 0. Checking the length is the best option to follow as it will cover both if the slice is empty or if the slice is nil.

Meanwhile, when designing interfaces, we should avoid distinguishing nil and empty slices, which leads to subtle programming errors. When returning slices, it should make neither a semantic nor a technical difference if we return a nil or empty slice. Both should mean the same thing for the callers. This principle is the same with maps. To check if a map is empty, check its length, not whether it’s nil.

Expand Down Expand Up @@ -1322,7 +1322,7 @@ A data race occurs when two or more goroutines simultaneously access the same me
We can prevent a data race from happening using different techniques. For example:

* Using the `sync/atomic` package
* In synchronizing the two goroutines with an ad how data structure like a mutex
* In synchronizing the two goroutines with an ad hoc data structure like a mutex
* Using channels to make the two goroutines communicating to ensure that a variable is updated by only one goroutine at a time

#### Race Condition
Expand Down

0 comments on commit c3d7346

Please sign in to comment.