The difference the tour offers does not actually change v := &Vertex{3, 4} to v:= Vertex{3, 4} , but rather changes the definitions of these two methods so that they work on values โโinstead of pointers. So, for example, for Scale , func (v *Vertex) Scale(f float64) {... becomes func (v Vertex) Scale(f float64) {... (note that (v *Vertex) , the pointer value becomes (v Vertex) , a value without a pointer). In both cases, you must leave the v declaration as v := &Vertex{3, 4} .
You will notice that in the first case, when the methods take pointers, the output is &{15 20} 25 . However, when methods take values, not pointers, the output is &{3 4} 5 .
In both cases, v is a pointer to a Vertex object. In the first case, the pointer is passed to the methods, and everything works as expected - any changes made to the Vertex object are made with the original value, so these changes are saved after the method returns. In the second case, although v is still a pointer, the Go compiler is smart enough to convert v.Scale(5) to (*v).Scale(5) , where v dereferenced and the resulting value is passed to Scale .
source share