Golang landmines
gist.github.com · 454 words · saved by 1 readers
Golang landmines. GitHub Gist: instantly share code, notes, and snippets.
There are three easy to make mistakes in go. I present them here in the way they are often found in the wild, not in the way that is easiest to understand. All three of these mistakes have been made in Kubernetes code, getting past code review at least once each that I know of. Loop variables are scoped outside the loop. What do these lines do? Make predictions and then scroll down. func print(pi *int) { fmt.Println(*pi) } for i := 0; i < 10; i++ { defer fmt.Println(i) defer func(){ fmt.Println(i) }() defer func(i int){ fmt.Println(i) }(i) defer print(&i) go fmt.Println(i) go func(){…
saved by
related reading
- Frequently Asked Questions (FAQ) - The Go Programming Languagego.dev
- Profiling Go programs with pprofjvns.ca
- Writing Better Go: Lessons from 10 Code Reviews - Speaker Deckspeakerdeck.com
- Writing Better Go: Lessons from 10 Code Reviews - Speaker Deckspeakerdeck.com
- Effective Go - The Go Programming Languagego.dev
- Go go-to guide · YourBasicyourbasic.org
- Notes on structured concurrency, or: Go statement considered harmful - njs blogvorpus.org
- Pointers & errors | Learn Go with testsquii.gitbook.io
- Demystifying Function Parameters in Go- Alex Edwardsalexedwards.net
- NilAway: Practical Nil Panic Detection for Gouber.com
- Four Days of Go – Evan Millerevanmiller.org
- A half-hour to learn Rustfasterthanli.me