Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.