Open ainar-g opened 3 years ago
An interesting gotcha I found recently, which could be dangerous in overly-dynamically-typed code:
ch := make(chan []int, 3) ch <- []int{10, 20, 30} close(ch) for s := range <-ch { fmt.Println(s) }
As opposed to:
[10 20 30]
This prints:
0 1 2
Because what the user actually wanted to write is probably:
for s := range ch { fmt.Println(s) }
Without the <-.
<-
An interesting gotcha I found recently, which could be dangerous in overly-dynamically-typed code:
As opposed to:
This prints:
Because what the user actually wanted to write is probably:
Without the
<-
.