4 ms·
I'm not familiar with Go and I'm confused by the fact that even though the returned variable is named, e.g. "ch", that name is never mentioned in the function b
by hota_mazi 9y ago
I'm not familiar with Go and I'm confused by the fact that even though the returned variable is named, e.g. "ch", that name is never mentioned in the function body.
What am I missing?
- dullgiulio 9y agoNaked returns. Basically, you just write "return" and that returns the values declared as named return parameters. If they are never mentioned in the body you probably have a return of the default nil value for the named return variables. But then at least one return is not naked and returns some value, discarding the named one. I think it's a bad use of named returns.
- masklinn 9y agoNothing. The named return value is default-initialised (zero-initialised) before the function body (you don't have to assign to it, you can just modify it in place), and if you don't explicitly return a different value it will be returned regardless of you using it or not.