I’m reading the Go language specification. The section on comments states:
Line comments start with the character sequence
//
and stop at the end of the line. A line comment acts like a newline.
What is the point of specifying that a line comment acts like a newline? Couldn’t line comments simply act like empty strings?
Lines (except the last) end in a newline anyway, so any line (except the last) will act like two consecutive newlines. If the last line has a line comment, then it can also safely act like an empty string.
1
Some potential reasons:
-
they consider the new line as part of the comment
-
they don’t want any ambiguity, especially that there is another kind of comment which is sometimes equivalent to a space and sometimes equivalent to a new line.
2