Hacker News new | past | comments | ask | show | jobs | submit login

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?




Naked 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.


Nothing.

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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: