Last active
October 30, 2015 12:58
-
-
Save daniellowtw/fa819a93c4eb288fb3cd to your computer and use it in GitHub Desktop.
Golang good and bad parts
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
// Cannot use short assignments when dealing with structs | |
package main | |
type foo struct { | |
stuff int | |
} | |
func main() { | |
foo.stuff, a := 1,2 | |
println(a) | |
} |
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
// Go is not an OOP language! | |
// Making both static functions and methods | |
package main | |
type foo struct { | |
stuff int | |
} | |
func (f foo) Bar () { | |
println(f.stuff) | |
} | |
func Bar(){ | |
var f foo // <== this allocates memory for foo and "label" it as that? | |
f.Bar() // which allows us to call this | |
} | |
func main() { | |
myFoo := foo{42} | |
myFoo.Bar() // 42 | |
Bar() // 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment