user1150125
user1150125

Reputation: 89

go programming language bracket pair style

I'm just new to learn Go, when I try my first hello world with this style:

func main()
{
      ...somemagic...
}

and the 6g compiler says that's wrong.

But with this style:

func main(){
      ...somemagic...
}

That's OK.

Is the first bracket pair style illegal in Go?

Upvotes: 4

Views: 432

Answers (2)

zzzz
zzzz

Reputation: 91193

Yes, the first form can't work because of the semicolon injection rules.

Upvotes: 1

Mostafa
Mostafa

Reputation: 28086

Yes. That's a result of automatic semicolon insertion in Go.

By the way, Go developers format their code using gofmt and follow that formatting.

Upvotes: 8

Related Questions