News for hackers. Stuff that matters.
Re:Benefits of named return values in Go by 013a on Friday June 30, 2017 @12:33AM (#14668641)
I'm not the most proficient Go developer, but aren't the two examples doing two different things?

In the first way, each branch allocates its own objectInfo struct. In the second way, all the branch exits share the same single objectInfo struct which I assume is implicitly initialized to the zero value by the compiler.

Functionally these are the same, but couldn't you achieve the same results without named return values by just allocating a single objectInfo at the top of the function and returning it?

Re:Benefits of named return values in Go by blahedo on Friday June 30, 2017 @03:01AM (#14669051)
This was my observation as well, but even more importantly, in the given examples they're naming a value to get this benefit, but then never actually referring to the value by name. This is contorted at best.
Re:Benefits of named return values in Go by Gonzih on Friday June 30, 2017 @05:35AM (#14669553)
Yes, you are correct. Doing var return MyStruct {} at the beginning of the function would do exactly the same thing as naming return value.
Re:Benefits of named return values in Go by fwessels on Friday June 30, 2017 @02:55AM (#14669022)
Yes, you can, but just naming the return variable takes care of this.
Re:Benefits of named return values in Go by geekme on Friday June 30, 2017 @12:58AM (#14668722)
Yes it will work.