+14  A: 

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

SingleShot
+1 I like that. Space for comment; no-space for commented out code.
Robert Cartaino
Agreed, spaces for comments, no spaces for commented-out code.
Robert Harvey
It tends to be that you have an extra non-space character after the marker symbol to indicate special treatment of the comment. Doxygen with /** for example; I've seen variants with @ and other ones.
Jonathan Leffler
+6  A: 

In the last 24 years, I've developed and maintained code professionally in C, C++, Pascal, BASIC, Java, Perl, Objective C, Bourne shell, bash, csh, tcsh, and assembly for 68K, PowerPC and x86. During this time, I've noticed a few things...

  1. Comments with leading spaces are at least 1000 times more common than comments without spaces. Missing leading spaces in comments are most often typos due to hasty typing.

  2. I can't remember ever seeing comments in sample code in a professional book or manual without the space.

  3. The only professional developers I've known who routinely omit the leading space in comments grew up using a non-Western, ideographic writing system that doesn't use spaces.

  4. I have never, ever seen an official company coding style that tells people to omit the leading space in comments.

So all in all, I would say the overwhelming evidence is that a space after the line-comment is preferred.

Bob Murphy
Wow, I hadn't noticed the connection between being a native Chinese-reader and comment (and code) formatting, but it rings true.
Novelocrat
+1  A: 

I mostly avoid having comments on the end of a line of code, because then the comments hang off the end and aren't as easy to parse when scanning. When I have a good reason, though, I like to use two spaces to separate code and comments (then one space after the comment marker). It just makes it easier for the eye...

Consider:

    int top;  // Index of the top of the stack.

versus:

    int top; // Index of the top of the stack.

Subjectively, it seems like two spaces just makes it easier to split up what's code and what's not.

Peter
The question is more about what goes after the // than what goes before - to be spaced out, or not to be spaced out?
Jonathan Leffler
It took me four re-reads to finally see what the difference was between your two samples. Guess it's not that important a difference to me :)
Mr. Shiny and New
+1  A: 

Well I have found the standard (according to Wikipedia) for commenting in Java. This is supposed to be "consistent with the Sun Microsystems Javadoc standards":

/**
 * Registers the text to display in a tool tip.   The text
 * displays when the cursor lingers over the component.
 * @param text  the string to display.  If the text is null, 
 *              the tool tip is turned off for this component.
 */

So I'm starting to think the standard is a space. Also, all the other examples have a space.

bennybdbc
+4  A: 

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;-).

Alex Martelli
A: 

I just came across StyleCop's SA1005 rule, which states:

A violation of this rule occurs when a single-line comment does not begin with a single space. For example:

private void Method1()
{
  //A single-line comment.
  //   A single-line comment.
}

The comments should begin with a single space after the leading forward slashes:

private void Method1()
{
  // A single-line comment.
  // A single-line comment.
}

Since StyleCop is in one way or another a Microsoft product, I'd say this qualifies as an official coding standard with respect to spaces in line-comments.

Mark Rushakoff