-
Notifications
You must be signed in to change notification settings - Fork 42
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
New slices are relevant #80
Comments
Thanks for the issue! It's interesting that you say this because I think what you ended up with in your second example is more or less exactly what my intentions was with this linter, to end up with code like that. To me it reads like this:
The first example you have is the one with most questions about. For reference, it's discussed at least in #33 and #71. In addition to what's said in #71 I can add that the reason for this is that each block should be seen as its own operation and could potentially even be its own function. Consider functional languages such as Haskell or Elixir, they don't even have The only thing that I can think of that would support alternative solutions and is yet on the wish list is to allow to cuddle variables that are used anywhere in the block (but still as long as only one is cuddled). See #24 and #50. If those were to be implemented and set to true, this would be an alternative. func evenFilter(a*A) []int{
newSlice := make([]int, 0, len(a.slice))
for _, v := range a.slice {
if v % 2 == 0 {
newSlice = append(newSlice, v)
}
}
return newSlice
} And this, although I don't see why one would assign a separate variable to only used it in func evenFilter(a*A) []int{
slice := a.slice
newSlice := make([]int, 0, len(slice))
for _, v := range slice {
if v % 2 == 0 {
newSlice = append(newSlice, v)
}
}
return newSlice
} So to sum it up, there will not be support to cuddle multiple statements before blocks because it's one of the core ideas to have each block separated. Although the possibility to cuddle variables above a block that's used somewhere within |
It is warned by the wsl if I declare a new slice before the range loop.
I expect it's not warned.
https://play.golang.org/p/VEpWPSRTNfj
The following codes are uncomfortable.
The text was updated successfully, but these errors were encountered: