Skip to content

Instantly share code, notes, and snippets.

@tucnak
Created October 28, 2015 09:24
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 tucnak/db857a6944c0ba5007df to your computer and use it in GitHub Desktop.
Save tucnak/db857a6944c0ba5007df to your computer and use it in GitHub Desktop.
I am really into variable shadowing in Go!
package main
import "fmt"
func Secret() (int, error) {
return 42, nil
}
func main() {
number := 0
fmt.Println("before", number) // 0
{
// meet the shadowing
number, err := Secret()
if err != nil {
panic(err)
}
fmt.Println("inside", number) // 42
}
fmt.Println("after", number) // 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment