I was just wondering why these brackets haven't been removed after running go fmt, does their use have a function?
package main
import "fmt"
func main() {
fmt.Println("Hello, 世界")
{
{
{
}
}
}
}
Example here, thanks.
Brackets on their own denote code Blocks. From the spec:
A block is a possibly empty sequence of declarations and statements within matching brace brackets.
These are part of the Go syntax, and go fmt
formats them according the its formatting rules.
They basically function like an internal namespace, so any definition(s) you put in between an encapsulating brace will not be visible outside of it.
// ... other code above ...
{
a := 5 // declare a
}
a = 5 // compiler error, a is undeclared
And plus formatting tools such as gofmt
or autopep8
(for python) do not modify a given file beyond adding/removing whitespace or newline characters to already existing code.