-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
doc: add C++ style comments to the style guide #17617
Conversation
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.) |
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. |
@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
Outdated
@@ -33,6 +34,21 @@ these rules: | |||
|
|||
`char* buffer;` instead of `char *buffer;` | |||
|
|||
## C++ style comments | |||
|
|||
Always use C++ style comments (`//`) for single line and multi-line comments. |
There was a problem hiding this comment.
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.
50b5992
to
3a1d18f
Compare
PR updated. Thanks for the suggestion @refack |
There was a problem hiding this comment.
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.
CPP_STYLE_GUIDE.md
Outdated
Examples: | ||
|
||
```c++ | ||
// a single line comment |
There was a problem hiding this comment.
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 😄
There was a problem hiding this comment.
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!
3a1d18f
to
69dc7ac
Compare
@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?
|
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. |
CPP_STYLE_GUIDE.md
Outdated
|
||
|
||
// Multi-line comments | ||
// should also follow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
follow -> use
69dc7ac
to
6a0c309
Compare
Pull request updated with latest suggestions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some nits.
CPP_STYLE_GUIDE.md
Outdated
|
||
|
||
// Multi-line comments | ||
// should also use C++ |
There was a problem hiding this comment.
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++
.
CPP_STYLE_GUIDE.md
Outdated
|
||
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 in the immediate vicinity of it or when changing/improving those |
There was a problem hiding this comment.
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
CPP_STYLE_GUIDE.md
Outdated
```c++ | ||
// A single line comment. | ||
|
||
|
There was a problem hiding this comment.
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.
CPP_STYLE_GUIDE.md
Outdated
@@ -33,6 +34,27 @@ these rules: | |||
|
|||
`char* buffer;` instead of `char *buffer;` | |||
|
|||
## C++ style comments | |||
|
|||
Use C++ style comments (`//`) for both single line and multi-line comments. |
There was a problem hiding this comment.
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.
6a0c309
to
8e7a098
Compare
@apapirovski done :) |
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>
Landed in a17f426 |
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>
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>
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>
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>
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