Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Can we allow C++ comments in C++ code?

40 views
Skip to first unread message

Nicholas Nethercote

unread,
Apr 1, 2012, 9:27:41 PM4/1/12
to JS Internals list
Hi,

C++ comments, e.g.:

// This is a comment.

aren't allowed in SpiderMonkey C++ code. At least, I don't think they are.

The C coding style document
(https://wiki.mozilla.org/JavaScript:SpiderMonkey:C_Coding_Style) says
to never use C++ comments, and the C++ coding style document
(https://wiki.mozilla.org/JavaScript:SpiderMonkey:C%2B%2B_Coding_Style)
inherits from the C coding style document and doesn't say anything on
the matter.

Assuming they are disallowed, can we change this? C comments are
inferior in just about every way. In particular, I cry a little every
time I have to spend 4 lines to write a two line comment:

/*
* line 1
* line 2
*/

instead of:

// line 1
// line 2

Furthermore, C++ comments have (unsurprisingly) crept in all over the place.

I'd also be happy to allow C++ comments in C code within SpiderMonkey,
since that's valid in C99 and widely supported, but that one matters a
lot less to me.

Nick

Jeff Walden

unread,
Apr 2, 2012, 2:33:56 PM4/2/12
to
On 04/01/2012 06:27 PM, Nicholas Nethercote wrote:
> C++ comments, e.g.:
>
> // This is a comment.
>
> aren't allowed in SpiderMonkey C++ code. At least, I don't think they are.

I don't think //-style comments are disallowed. They're less common because /**/-style necessarily predominated for so long, and consistency meant most people (but not everyone) kept using them. I remember asking about this a couple years or so ago and hearing both are fine now.

I think /**/-style comments with mostly-blank lines at start and end are a little more clearly separated from surrounding code, making them better for longer overview-ish comments. But I don't really want to prescribe a particular style on the point even if restricted to that subset, or any other.

Jeff

Nicholas Nethercote

unread,
Apr 2, 2012, 10:10:18 PM4/2/12
to Jeff Walden, dev-tech-js-en...@lists.mozilla.org
On Mon, Apr 2, 2012 at 11:33 AM, Jeff Walden <jwald...@mit.edu> wrote:
>
> I don't think //-style comments are disallowed.

EXCELLENT

Nick

David Anderson

unread,
Apr 2, 2012, 10:08:06 PM4/2/12
to dev-tech-js-en...@lists.mozilla.org
For what it's worth, we've been requiring // style in ion/*

-David

On 04/02/2012 07:10 PM, Nicholas Nethercote wrote:
> On Mon, Apr 2, 2012 at 11:33 AM, Jeff Walden<jwald...@mit.edu> wrote:
>>
>> I don't think //-style comments are disallowed.
>
> EXCELLENT
>
> Nick
> _______________________________________________
> dev-tech-js-engine-internals mailing list
> dev-tech-js-en...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-tech-js-engine-internals

Brendan Eich

unread,
Apr 3, 2012, 11:35:09 AM4/3/12
to David Anderson, dev-tech-js-en...@lists.mozilla.org
Does anyone use the old Unix-style major comments in IonMonkey code?

I agree with Waldo, they help for large-comment readability, absent
colorization or other aids. The // style runs into code and / is an
operator. It's also visually light. This is subjective of course, and

// lots to say
// here but no time
// to say it all
code = goes + here;

can be easier to read. The Unix-style major comments waste lines on /*
and */ and make a wall of stacked stars, which can get in the way.

FWIW I think both are fine, and have been since we switched to C++. The
style guide never got updated from its C roots, 'sall.

/be

David Anderson wrote:
> For what it's worth, we've been requiring // style in ion/*
>
> -David
>
> On 04/02/2012 07:10 PM, Nicholas Nethercote wrote:
>> On Mon, Apr 2, 2012 at 11:33 AM, Jeff Walden<jwald...@mit.edu>
>> wrote:
>>>
>>> I don't think //-style comments are disallowed.
>>

Dave Mandelin

unread,
Apr 3, 2012, 8:42:31 PM4/3/12
to JS Internals list
Looks like we have a general consensus on allowing either style. I was going to edit the style guide, but it turns out it already doesn't say anything about comment type. FWIW, I grew up with //-comments, so I like them, although I'm fairly used to /* now.

Dave Mandelin

unread,
Apr 3, 2012, 8:42:31 PM4/3/12
to mozilla.dev.tech.j...@googlegroups.com, JS Internals list
On Sunday, April 1, 2012 6:27:41 PM UTC-7, Nicholas Nethercote wrote:
0 new messages