That's the FAQ. The official Language Specification says nothing about this little gimmick, at least in the if-else section: https://go.dev/ref/spec#If_statements
You'd think one would want to look for it in that instead of an FAQ page.
If you looked at the spec which provides simple, valid examples that work, then why would you spend hours writing different code wondering why it doesn’t work?
All of this is quite natural once you use the language. in fact, it was designed this way in response to the way it was being used.
It is not appropriate for the spec to constantly reiterate concepts that have already been introduced, but rather it should precisely define each concept once. If you want to learn a language from its spec then it behooves you to consider the document as a whole. That requires a lot of mental overhead and I think most people are better off learning from examples and tutorials rather than reading a language spec.
dartharva|3 years ago
You'd think one would want to look for it in that instead of an FAQ page.
enneff|3 years ago
The section you linked does explain it, btw.
Note there is no newline or semicolon between Block and the optional “else” clause, and a Block is thusly defined: So that being the case I’m not sure why you’d assume it’s valid to put a newline after the trailing “}” of the Block, before the “else”.The other factor at play here is the treatment of semicolons: https://go.dev/ref/spec#Semicolons
All of this is quite natural once you use the language. in fact, it was designed this way in response to the way it was being used.
It is not appropriate for the spec to constantly reiterate concepts that have already been introduced, but rather it should precisely define each concept once. If you want to learn a language from its spec then it behooves you to consider the document as a whole. That requires a lot of mental overhead and I think most people are better off learning from examples and tutorials rather than reading a language spec.