Skip to content

Instantly share code, notes, and snippets.

@ORESoftware
Created February 11, 2020 05:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ORESoftware/a6243ce1039cea7e49a22ec8daf90a82 to your computer and use it in GitHub Desktop.
Save ORESoftware/a6243ce1039cea7e49a22ec8daf90a82 to your computer and use it in GitHub Desktop.
initializing vars in Golang

In this simple golang example it appears that we don't need to initialize the wg variable. Why do we do this:

var wg sync.WaitGroup
func main() {
        // do some stuff
        wg.Wait()  //     // blocks/waits for waitgroup
}

instead of this:

var wg sync.WaitGroup = sync.WaitGroup{}  // is this initialization implicit, and why?

func main() {
    // ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment