Attempt to clarify the behaviour - your problem is happening because of the 
line in the specification in https://golang.org/ref/spec#Semicolons which 
states 

*When the input is broken into tokens, a semicolon is automatically 
inserted into the token stream immediately after a line's final token if 
that token is ... one of the operators and delimiters ++, --, ), ], or }*


so this is fine 

package main; 

 

import "fmt";

 

func main() {

    fmt.Printf("hello, world!\n");

}

and this is not :


package main; 

 

import "fmt";

 

func main() 

{

    fmt.Printf("hello, world!\n");

}


because the second case is converted to  :

package main; 

 

import "fmt";

 

func main();

{

    fmt.Printf("hello, world!\n");

}


because of the rule given above in the spec - that is there's an insertion 
of a semicolon after the () in the func ...


You probably already got that - the question is "why is it such a sissy" 
and I think the short answer is - because *the spec is aiming to create a 
syntax/grammar that is parsable one line at a line without reading forward*

Go not only borrows obviously from C, but also maybe less obviously from 
Pascal (and those ETH Zuritch / Nicolas Wurth family of languages) - one 
thing that is influenced by this is the form of some variable declarations 
.. I think(opinion) another influence is the original Pascal compiler 
design that the compiler could produce output from a single pass of a 
program. One of the design goals of Go was for quick compilation - so maybe 
we can see the thought process here.. It's not unreasonable to say it's 
gone too far.

So as a consequence of the aim to make the compiler "simple" Allman style 
is *essentially illegal -* but not by choice - it's just a consequence of 
streamlined parser design - not because we don't like Allman style.

Go also enforces a single style - as other's have said that's unlikely to 
change - a lot of use don't like/have complaints about the chosen style but 
accept it because it enables a consistent formatting style no matter who 
wrote the code - so accepting that - even if the compiler accepted the 
second form of the simple program (it doesn't) - it would still gofmt it to 
the other style..


So it's a trade off - a single style (that is a lot like K&R) so that all 
programs are formatted the same and to ease compilation.

  

  

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to