by KevinMS · 3y ago · 0 comments
Maybe I'm weird but one of the greatest things about gofmt is that it doesn't murder "padded blocks", like so many formatters out there.
For example, given this
func main() {
fmt.Println("a")
fmt.Println("b")
fmt.Println("c")
fmt.Println("d")
}
gofmt will simply collapse the double line in the middle.However, this tool will do this
func main() {
fmt.Println("a")
fmt.Println("b")
fmt.Println("c")
fmt.Println("d")
}
How is having chunks of code smashed into the tops and bottoms of a blocks good for improving readability? Why should the visual relationship between and main() and "a" be stronger than between "b" and "c" if the author doesn't want it?How is having a random newline at the top and bottom where there is already a clear separation between function signature and implementation via braces and the guide of the first indentation, helping readability?
All it does is steal valuable vertical space away from things that matter.
I'm not saying that there's never a reason for to have extra blank lines. But your example isn't it.
Are there Go codebases that stick to the formatting you show, out of curiosity?
Either way, please file a bug. Perhaps others can chime in there if they also use the same style.
Support for allowing configuration of such a thing would be a misfeature if I was to be asked.
Are you referring to C style if statements where you can elide the braces?
In go the braces are mandatory, so I don't think that really applies.