You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to see a parallel to the "Single var declarations should not be grouped with parentheses" rule.
Where
foo:=1bar:=2baz:=3
and potentially
varfoo=1varbar=2varbaz=3
becomes
var (
foo=1bar=2baz=3
)
The rationale is to have the formatter do the inverse of what it already does.
During editing, if I have a block of multiple declarations, then reduce it to one, the formatter will collapse it to the short form. But if I add declarations back into the same area of code, I have to reverse that process manually.
I don't think this is something people would want to have enabled all the time, nor would they by default, so I'm gonna say it should depend on #251 even if it gets accepted and someone decides to implement it.
Also, I want to acknowledge that this rule might be a lot tricker to implement than the existing one. And that most code written with adjacent shortform declarations is likely done so intentionally.
Admittedly this is usually only something I notice when I'm refactoring code too rapidly without thinking things through first 😅, but I figured it might be worth bringing up.
The text was updated successfully, but these errors were encountered:
We already do this for top-level declarations. Hence I assume you mean that you want the grouping to happen for local declarations too.
I fear this would be too invasive. It's fairly common to need to declare multiple short variables with := inside a function, and while I agree that vertical alignment is nice, forcing the user to need two extra lines for the opening and closing of the group is not great.
For example, take this func from Go's src/io/io.go:
func (discard) ReadFrom(r Reader) (n int64, err error) {
bufp := blackHolePool.Get().(*[]byte)
readSize := 0
for {
readSize, err = r.Read(*bufp)
n += int64(readSize)
if err != nil {
blackHolePool.Put(bufp)
if err == EOF {
return n, nil
}
return
}
}
}
You suggest that we format it as:
func (discard) ReadFrom(r Reader) (n int64, err error) {
var (
bufp = blackHolePool.Get().(*[]byte)
readSize = 0
)
for {
readSize, err = r.Read(*bufp)
n += int64(readSize)
if err != nil {
blackHolePool.Put(bufp)
if err == EOF {
return n, nil
}
return
}
}
}
Personally, I think that is mildly worse. The formatting rules need to be clear wins so that the formatting is consistent across developers and the git diff churn is worth it. I'm afraid this wouldn't meet that bar.
I'd like to see a parallel to the "Single var declarations should not be grouped with parentheses" rule.
Where
and potentially
becomes
The rationale is to have the formatter do the inverse of what it already does.
During editing, if I have a block of multiple declarations, then reduce it to one, the formatter will collapse it to the short form. But if I add declarations back into the same area of code, I have to reverse that process manually.
I don't think this is something people would want to have enabled all the time, nor would they by default, so I'm gonna say it should depend on #251 even if it gets accepted and someone decides to implement it.
Also, I want to acknowledge that this rule might be a lot tricker to implement than the existing one. And that most code written with adjacent shortform declarations is likely done so intentionally.
Admittedly this is usually only something I notice when I'm refactoring code too rapidly without thinking things through first 😅, but I figured it might be worth bringing up.
The text was updated successfully, but these errors were encountered: