golang / tour

[mirror] A Tour of Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

tour: Struct literals example is confusing

tdurtschi opened this issue · comments

Context: https://go.dev/tour/moretypes/5

The print statement should log each Vertex in the order it was created. I found the output very confusing until I realized the structs were shuffled in the call to Println.

var (
	v1 = Vertex{1, 2}  // has type Vertex
	v2 = Vertex{X: 1}  // Y:0 is implicit
	v3 = Vertex{}      // X:0 and Y:0
	p  = &Vertex{1, 2} // has type *Vertex
)

func main() {
	fmt.Println(v1, p, v2, v3) // Should be fmt.Println(v1, v2, v3, p)
}