-
Notifications
You must be signed in to change notification settings - Fork 291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Discussion on named return values #831
Comments
@adlerjohn points out two drawbacks to using named return values:
I don't understand the second drawback (re: global variables). To my knowledge, a named return value is declared inside the scope of the function so a function that uses named return values can still be pure. |
I almost never use them for bare returns, but sometimes I like adding the names as documentation and saving me a line or two of variable declarations. func() (has bool) {}
func(t []int) (s []int) {
for _, i := range t {
if i == 4 {
s = append(s, i)
}
}
return s
} tbh though I realllllllyyyy don't care. if someone has a strong preference we can do that as long as we do not change tendermint code |
sorry, hit control + enter at the wrong time and it closed the issue... |
That's a really good point. Any decision we reach here would only be productive if enforced through linters. I think minimizing the diff between celestia-core and tendermint/tendermint is a more important goal than codebase consistency with regard to this minor code style rule. My preference would be to remain consistent with whichever linters are enforced by https://github.com/tendermint/tendermint/blob/main/.golangci.yml |
Golang has named return values so a function can be written with unnamed return values:
or named return values
celestia-core currently uses both forms which leads to code style nits in PR comments. If we reach a decision on which form is preferred, we can enforce it via linters and avoid this type of code style inconsistency.
Ref:
Original discussion: #820
The text was updated successfully, but these errors were encountered: