Updated CommonMistakes (markdown)

Mingliang Liu 2018-04-19 20:53:41 -07:00
parent f4f69696b9
commit 88d63a97c0

@ -12,7 +12,7 @@ When new programmers start using Go or when old Go programmers start using a new
When iterating in Go, one might also be tempted to use goroutines to process data in parallel. For example, you might write the following code: When iterating in Go, one might also be tempted to use goroutines to process data in parallel. For example, you might write the following code:
```go ```go
for val := range values { for _, val := range values {
go val.MyMethod() go val.MyMethod()
} }
``` ```
@ -20,7 +20,7 @@ for val := range values {
or if you wanted to process values coming in from a channel in their own goroutines, you might write something like this, using a closure: or if you wanted to process values coming in from a channel in their own goroutines, you might write something like this, using a closure:
```go ```go
for val := range values { for _, val := range values {
go func() { go func() {
fmt.Println(val) fmt.Println(val)
}() }()
@ -31,7 +31,7 @@ The above for loops might not do what you expect because their ` val ` variable
The proper way to write that closure loop is: The proper way to write that closure loop is:
```go ```go
for val := range values { for _, val := range values {
go func(val interface{}) { go func(val interface{}) {
fmt.Println(val) fmt.Println(val)
}(val) }(val)