Take the 2-minute tour ×

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.

share|improve this question
Might be related to the automatic insertion of ; at the end of lines. –  Mat Jun 2 '13 at 12:02
add comment

1 Answer

up vote 2 down vote accepted

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.

share|improve this answer
It can't be the first reason because then a line comment on the last line would not be a line comment. –  Randomblue Jun 2 '13 at 12:01
@Justin, considering the Unix origin of Go designers and the fact that Unix definition of text file is light but requires the last line to be terminated by a new line (i.e. it is a terminator, not a separator; that constraint is also present in C BTW), I'd not be so sure. –  AProgrammer Jun 2 '13 at 12:05
add comment

Your Answer


