Created
October 28, 2015 09:24
-
-
Save tucnak/db857a6944c0ba5007df to your computer and use it in GitHub Desktop.
I am really into variable shadowing in Go!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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