Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

go programming language bracket pair style

Tags:

go

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?

like image 690
user1150125 Avatar asked Jan 17 '23 18:01

user1150125


2 Answers

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.

like image 163
Mostafa Avatar answered Jan 30 '23 19:01

Mostafa


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

like image 35
zzzz Avatar answered Jan 30 '23 20:01

zzzz