The Go Bestiary: Bugs, gotchas and guidelines for go programmers by Kenneth Grant

The Go Bestiary: Bugs, gotchas and guidelines for go programmers by Kenneth Grant

Author:Kenneth Grant [Grant, Kenneth]
Language: eng
Format: azw3
Publisher: Cipher Press
Published: 2017-10-08T04:00:00+00:00


Shadowing

Be careful when using the automatic assignment operator := that you don't accidentally shadow variables from the outer block. In the case below err is created twice, and if you relied on err being set in the outside scope it would not be. In most cases this isn't a problem but it's something to be aware of. Most linters warn about any dangerous instances of shadowing so if you use a linter it is not usually a problem in practice.

// err is created err := f() if err != nil { // err is recreated - outer err is not updated v, err := f() }



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.