Old habits die hard. I find switching between Python and C syntax confusing. Especially due to the lack of semicolons as terminators and brackets to determine a new level of scope in Python. Go’s syntax was even more diffuse, they introduced optional semicolons some places; to separate statements rather than terminate them.
Go’s approach will most likely change. Rob Pike introduced a proposal which basically removes them from the source, as terminators and seperators. Except in cases like the for loop and similar. Which is better then the way semicolons were used before. Either or neither, not both!
Snippets from the mailing list:
The language BCPL, an ancestor to B, which is an ancestor to C, had an interesting approach to semicolons. It can be summarized in two steps. First, the formal grammar requires semicolons in statement lists. Second, a lexical (not syntactic) rule inserts semicolons.
- In the formal grammar, semicolons are terminators, as in C.
- A semicolon is automatically inserted by the lexer if a line’s last token is an identifier, a basic literal, or one of the following tokens: break continue fallthrough return ++ — ) }
- A semicolon may be omitted before a closing ) or } .
To make gofmt do this automatically we can use gofmt -oldprinter=false -w *.go. Remember is not in release branch yet.