Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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
1  
Might be related to the automatic insertion of ; at the end of lines. –  Mat Jun 2 '13 at 12:02

1 Answer 1

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

 
discard

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.