I realize that this rule might differ from one company's coding standards to another, but in general, which is preferred?
With a space after the line-comment:
int foo = Bar(quux + 1); // compensate for quux being off by 1 foo = Bar(quux + 1) # compensate for quux being off by 1
No space after the line comment:
int foo = Bar(quux + 1); //compensate for quux being off by 1 foo = Bar(quux + 1) #compensate for quux being off by 1
I haven't been able to find anything online regarding this aspect of coding style. My guess is that including a space is the preferred style for all languages, but I'd like some "hard evidence" to confirm or deny this.
Write comments in English. For a block comment with multiple paragraphs, add a blank line between paragraphs with a single comment tag preceding a blank line. For inline comments, leave at least two spaces between the code and the comment.
Summary of comment types: use // for a single line. Everything from the // to the end of that line of the file is ignored by the program and is only for use by the human reader of the code.
// Single-line comments The comment begins with a double slash (//) and ends at a newline character (\n), a carriage return (\r), or the end of the file.
I've developed software in many languages for about 10 years on projects large and small. I have yet to see anyone intentionally not use a space. In the scheme of things it doesn't really matter that much (after all, we all know those are comments and can read them), but I do think the no-space version looks similar to commented-out code and requires an extra millisecond of brain power to confirm it is a comment :-)
Python's official style guide, PEP 8, is very clear about this issue:
Each line of a block comment starts with a # and a single space (unless it is indented text inside the comment).
and:
Inline comments should be separated by at least two spaces from the statement. They should start with a # and a single space.
This confirms everybody's anecdotal evidence, but I think this is the first answer to quote "some official or otherwise published coding standards" as requested;-).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With