A lot of examples out there (like this) show something like:
type person struct {
name string
age int
}
func NewPerson(n string, a int) *person {
p := person{n, a}
return &p
}
Whilst I'm comfortable with the mechanics of the above, there seems to be an idiom of always returning a pointer to the new struct.
Why wouldn't you simply always return the actual struct itself, rather than a pointer to it?
The struct is small, and future mutability doesn't come into it as mentioned in this question. Also, that question doesn't specifically address the constructor idiom. Is it all about perceived efficiency and memory?