[Learning] Should I define methods on values or pointers?
Stack Overflow: https://stackoverflow.com/questions/25382073/defining-golang-struct-function-using-pointer-or-not
Can someone explain to me why appending to an array works when you do this:
func (s *Sample) Append(name string) {
d := &Stuff{
name: name,
}
s.data = append(s.data, d)
}
But not when you do this:
func (s Sample) Append(name string) {
d := &Stuff{
name: name,
}
s.data = append(s.data, d)
}
Is there any reason at all why you would want to use the second example.