I just started with GoLang. I have noticed there are some initializations like this
agentUi := &f.Foo{
Reader: os.Stdin,
Writer: os.Stdout,
ErrorWriter: os.Stderr,
}
Coming from a c++ background , I am under the impression the reason above was done because the developer wanted to create a pointer agentUi instead of an object where he could have done something like this
agentUi := f.Foo{
Reader: os.Stdin,
Writer: os.Stdout,
ErrorWriter: os.Stderr,
}
so basically making sure that the object is still valid after the scope ends.In short create the object on the heap instead of the stack. Is that correct ?