Benefits of named return values in Go
blog.minio.io
Benefits of named return values in Go
1–10 of 146 posts
Re: Benefits of named return values in Go
#2Re: Benefits of named return values in Go
#3Re: Benefits of named return values in Go
#4Re: Benefits of named return values in Go
#5Re: Benefits of named return values in Go
#6Please don't go around naming all your returns just because today's compiler happens to generate better code with them. This is a compiler issue that I'm confident will be fixed one day, especially if you do the right thing and file an issue.
But by all means, if you're profiling and your inner loops are actually slowed down by this, then make the change. And add a comment so that someone might be able to change it back some day when the compiler's improved.
Re: Benefits of named return values in Go
#7 return { named_var_1, named_var_2 }
const { named_var_1, named_var_2 } = f()
But then I read the article.I don't know really what is going on in this article on a quick reading, but it builds by existing sense that go is a really cool language that I ought to get into.
I have no idea if anyone wants to help me understand, but in the last part where he changes to use a named return parameter, he says, you may also "enjoy the cleaner look of the source code, too". To me the only difference I see is the return name, to the right of the existing function signature. What was I missing that makes this actually cleaner?
Re: Benefits of named return values in Go
#8Or you could return a pointer...
Re: Benefits of named return values in Go
#9Re: Benefits of named return values in Go
#10I was going to post "But JS has this: return { named_var_1, named_var_2 } const { named_var_1, named_var_2 } = f() But then I read the article. I don't know really what is going on in this article on a quick reading, but it builds by existing sense that go is a really cool language that I ought to get into. I have no idea if anyone wants to help me understand, but in the last part where he changes to use a named retu…
e.g. https://play.golang.org/p/gdac5QR-wW
This can also be used to return the default value for a type by never assigning anything to the return value.