Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

mmarchini
Copy link
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-bot nodejs-github-bot added the doc Issues and PRs related to the documentations. label Dec 11, 2017
@addaleax
Copy link
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.)

@addaleax addaleax added the c++ Issues and PRs that require attention from people who are familiar with C++. label Dec 11, 2017
@bnoordhuis
Copy link
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
Contributor Author

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.

@@ -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.
Copy link
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 mmarchini force-pushed the docs/cpp_style_comment branch from 50b5992 to 3a1d18f Compare December 12, 2017 19:12
@mmarchini
Copy link
Contributor Author

PR updated. Thanks for the suggestion @refack

Copy link
Member

@BridgeAR BridgeAR left a 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.

Examples:

```c++
// a single line comment
Copy link
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
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 mmarchini force-pushed the docs/cpp_style_comment branch from 3a1d18f to 69dc7ac Compare December 13, 2017 13:12
@mmarchini
Copy link
Contributor Author

mmarchini commented Dec 13, 2017

@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
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.



// Multi-line comments
// should also follow
Copy link
Contributor

Choose a reason for hiding this comment

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

follow -> use

@mmarchini mmarchini force-pushed the docs/cpp_style_comment branch from 69dc7ac to 6a0c309 Compare December 13, 2017 21:06
@mmarchini
Copy link
Contributor Author

Pull request updated with latest suggestions

Copy link
Member

@apapirovski apapirovski left a comment

Choose a reason for hiding this comment

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

Just some nits.



// Multi-line comments
// should also use C++
Copy link
Member

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++.


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
Copy link
Member

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

```c++
// A single line comment.


Copy link
Member

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.

@@ -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.
Copy link
Member

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 mmarchini force-pushed the docs/cpp_style_comment branch from 6a0c309 to 8e7a098 Compare December 14, 2017 19:20
@mmarchini
Copy link
Contributor Author

@apapirovski done :)

@apapirovski
Copy link
Member

@apapirovski apapirovski 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
Member

Landed in a17f426

@BridgeAR BridgeAR closed this Dec 15, 2017
@addaleax addaleax 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>
@MylesBorins MylesBorins 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 free to 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++. doc Issues and PRs related to the documentations.
Projects
None yet
Development

Successfully merging this pull request may close these issues.