Skip to content

doc: add C++ style comments to the style guide - #17617

Closed
mmarchini wants to merge 1 commit into
nodejs:masterfrom
mmarchini:docs/cpp_style_comment
Closed

doc: add C++ style comments to the style guide#17617
mmarchini wants to merge 1 commit into
nodejs:masterfrom
mmarchini:docs/cpp_style_comment

Conversation

@mmarchini

Copy link
Copy Markdown
Contributor

Adds instructions on how to format C++ comments to the C++ style guide, as cpplint.py doesn't complain about C-style comments on the code and C++ style comments are the encouraged format.

There's a lot of C-style comments on the current code, and because of that new contributors may think C-style comments are the encouraged format for multi-line comments.

Checklist
Affected core subsystem(s)

doc

@nodejs-github-botnodejs-github-bot added the doc Issues and PRs related to the documentations. label Dec 11, 2017
@addaleax

Copy link
Copy Markdown
Member

There's a lot of C-style comments on the current code, and because of that new contributors may think C-style comments are the encouraged format for multi-line comments.

Are they discouraged by us (i.e. did somebody mention this as part of a review) or by somebody else?

I do sometimes like to use C style comments, and I've found that I tend to use C++ style comments for referring to the immediately following next line or two, and C style comments when referring to larger pieces of code. (And, although this is purely subjective observation, I think I'm not alone in that.)

@addaleaxaddaleax added the c++ Issues and PRs that require attention from people who are familiar with C++. label Dec 11, 2017
@bnoordhuis

Copy link
Copy Markdown
Member

Are they discouraged by us (i.e. did somebody mention this as part of a review) or by somebody else?

I usually request that people change them. 95% of our comments are C++-style so I'd like to see the other 5% go away over time. Many are from when node was still C-with-classes.

@mmarchini

Copy link
Copy Markdown
ContributorAuthor

Are they discouraged by us (i.e. did somebody mention this as part of a review) or by somebody else?

@bnoordhuis requested me to change from C to C++ style in some PRs. I didn't mind changing it and I think it's good to have a defined style for comments, but I thought C++ style was already an established standard in Node.

Maybe we should decide which style to follow before including it into CPP_STYLE_GUIDE.md, but it would be good to have a comment style documented to help new contributors to know how to format their comments.

Comment threadCPP_STYLE_GUIDE.md Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove the Always, and add a comment that there might still be "old" comment in the code:

Use C++ style comments (`//`) for both single line and multi-line comments.
Examples:
...
The codebase may contain old C style comments (`/* */`) from before this was the prefered style.

@mmarchini
mmarchiniforce-pushed the docs/cpp_style_comment branch from 50b5992 to 3a1d18fCompareDecember 12, 2017 19:12
@mmarchini

Copy link
Copy Markdown
ContributorAuthor

PR updated. Thanks for the suggestion @refack

@BridgeARBridgeAR left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but I would really like to add the upper case part and that the comments here start upper case as well. I always have to hold myself back not to complain about it when I do code reviews.

Comment threadCPP_STYLE_GUIDE.md Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we are on it - it would be nice to add that the start of a comment should also be upper cased 😄

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And a dot at the end!

@mmarchini
mmarchiniforce-pushed the docs/cpp_style_comment branch from 3a1d18f to 69dc7acCompareDecember 13, 2017 13:12
@mmarchini

mmarchini commented Dec 13, 2017

Copy link
Copy Markdown
ContributorAuthor

@BridgeAR@bnoordhuis something like that?

## C++ style comments
Use C++ style comments (`//`) for both single line and multi-line comments.
Comments should also start with uppercase and finish with a dot.
Examples:
```c++// A single line comment.// Multi-line comments// should also follow// C++ style comments.```
The codebase may contain old C style comments (`/* */`) from before this was the
preferred style.

Maybe we could also encourage people to update the style of comments on old code when working close to it?

The codebase may contain old C style comments (`/* */`) from before this was the
preferred style. Feel free to update old comments to the preferred style when working
on code close to it or when changing/improving those comments.

@bnoordhuis

Copy link
Copy Markdown
Member

Maybe change 'close to' to the more specific 'in the immediate vicinity of', otherwise sounds good.

A rule of thumb I use is that when a purely stylistic change results in a new hunk in the diff, it ain't worth doing.

Comment threadCPP_STYLE_GUIDE.md Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

follow -> use

@mmarchini
mmarchiniforce-pushed the docs/cpp_style_comment branch from 69dc7ac to 6a0c309CompareDecember 13, 2017 21:06
@mmarchini

Copy link
Copy Markdown
ContributorAuthor

Pull request updated with latest suggestions

@apapirovskiapapirovski left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some nits.

Comment threadCPP_STYLE_GUIDE.md Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we remove the double space before C++.

Comment threadCPP_STYLE_GUIDE.md Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/immediate vicinity of it/immediate vicinity

Comment threadCPP_STYLE_GUIDE.md Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The double line break feels unnecessary here.

Comment threadCPP_STYLE_GUIDE.md Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and elsewhere, s/single line/single-line.

Adds instructions on how to format C++ comments to the C++ style guide,
as `cpplint.py` doesn't complain about C-style comments on the code.
@mmarchini
mmarchiniforce-pushed the docs/cpp_style_comment branch from 6a0c309 to 8e7a098CompareDecember 14, 2017 19:20
@mmarchini

Copy link
Copy Markdown
ContributorAuthor

@apapirovski done :)

@apapirovski

Copy link
Copy Markdown
Contributor

@apapirovskiapapirovski added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Dec 14, 2017
BridgeAR pushed a commit to BridgeAR/node that referenced this pull request Dec 15, 2017
Adds instructions on how to format C++ comments to the C++ style guide,
as `cpplint.py` doesn't complain about C-style comments on the code.
PR-URL: nodejs#17617
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
@BridgeAR

Copy link
Copy Markdown
Member

Landed in a17f426

@addaleaxaddaleax removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Dec 29, 2017
MylesBorins pushed a commit that referenced this pull request Jan 8, 2018
Adds instructions on how to format C++ comments to the C++ style guide,
as `cpplint.py` doesn't complain about C-style comments on the code.
PR-URL: #17617
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
MylesBorins pushed a commit that referenced this pull request Jan 9, 2018
Adds instructions on how to format C++ comments to the C++ style guide,
as `cpplint.py` doesn't complain about C-style comments on the code.
PR-URL: #17617
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
@MylesBorinsMylesBorins mentioned this pull request Jan 10, 2018
MylesBorins pushed a commit that referenced this pull request Jan 23, 2018
Adds instructions on how to format C++ comments to the C++ style guide,
as `cpplint.py` doesn't complain about C-style comments on the code.
PR-URL: #17617
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
gibfahn pushed a commit that referenced this pull request Jan 24, 2018
Adds instructions on how to format C++ comments to the C++ style guide,
as `cpplint.py` doesn't complain about C-style comments on the code.
PR-URL: #17617
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++Issues and PRs that require attention from people who are familiar with C++.docIssues and PRs related to the documentations.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

11 participants

@mmarchini@addaleax@bnoordhuis@apapirovski@BridgeAR@refack@danbev@jasnell@cjihrig@MylesBorins@nodejs-github-bot