I have a struct called Calculator, with two properties: version and author. In order to instantiate this struct already initializing these methods, since Golang does not have constructors, the various tips that I found in the net indicate to create a NewCalculadora () method and later to use it to instanciar the Calculator. The method would look like this:
func NewCalculadora() *Calculadora {
return &Calculadora{autor:"Paulo Luvisoto",versao:1.0}
}
And all the pointers indicate the use of pointer, as above. But I have seen that this also works:
func NewCalculadora() Calculadora {
return Calculadora{autor:"Paulo Luvisoto",versao:1.0}
}
My question is: what's the problem with using this second way, without using a pointer?