doc: add C++ style comments to the style guide#17617
doc: add C++ style comments to the style guide#17617mmarchini wants to merge 1 commit intonodejs:masterfrom
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
There was a problem hiding this comment.
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 |
BridgeAR
left a comment
There was a problem hiding this comment.
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
There was a problem hiding this comment.
When we are on it - it would be nice to add that the start of a comment should also be upper cased 😄
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
69dc7ac to
6a0c309
Compare
|
Pull request updated with latest suggestions |
CPP_STYLE_GUIDE.md
Outdated
There was a problem hiding this comment.
can we remove the double space before C++.
CPP_STYLE_GUIDE.md
Outdated
There was a problem hiding this comment.
s/immediate vicinity of it/immediate vicinity
CPP_STYLE_GUIDE.md
Outdated
There was a problem hiding this comment.
The double line break feels unnecessary here.
CPP_STYLE_GUIDE.md
Outdated
There was a problem hiding this comment.
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.pydoesn'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