Skip to content

Instantly share code, notes, and snippets.

@jescalan
Last active August 29, 2015 14:03
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 jescalan/706a5372bdacb08870c6 to your computer and use it in GitHub Desktop.
Save jescalan/706a5372bdacb08870c6 to your computer and use it in GitHub Desktop.
Is there any reason to ever use the new keyword in go?
package main
import "fmt"
type Vertex struct {
X, Y int
}
func main() {
v := new(Vertex)
fmt.Println(v) // &{0, 0}
v.X, v.Y = 11, 9
fmt.Println(v) // &{11, 9}
t := &Vertex{}
fmt.Println(t) // &{0, 0}
t.X, t.Y = 11, 9
fmt.Println(t) // &{11, 9}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment