-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
Add guidelines on how to write effective comments #67
Comments
Thanks for addressing this important topic! Some initial observations:
|
Thanks for your feedback @MajorLift!
It depends how you do it. I usually use the github suggested merged commit messages in the squash commit. I don't want to have the PR description in the commit, it's not the place to have it as goals are very different. But I can clarify this in the changes.
Yes absolutely, these changes require to check the existing doc and rework some content.
Yes, or at least links to commonly used good practices.
Yes, like the already sourced Google or MS guidelines. Also the provided blog sources are more inspirations than actual sources of truth. The real source of truth will be what we write based on sources that can be sometimes considered as non official. The most important is that it fits our needs and makes sense.
This is an issue ticket, it raises the need for change and provides an example of the content we could include. It's a proposal and a reminder. Nothing set in stone here. |
Sounds good on all fronts!
The only point I'd want to add is that contributor docs are intended to be external-facing, so we might want to be extra careful about which sources we endorse or overall "polish," so to speak. |
Add info about how it can be helpful to have Gherkin formatted comments and Mermaid diagrams in PRs and code. See https://github.com/MetaMask/metamask-mobile/pull/8090/files#diff-c38099d02abf262b9f7c7bb6dd4e238c2114e6ff8515053c2097f200eee02936R28-R72 as an example |
Commenting Code: Why, Not How
Consider different kind of comments: code users comments (doc) vs code implementation comments (clarification comment).
Code Implementation Doc Comments Why, Not How: Code Shows How
// convert to hex value
, which is obvious from the codeaddHexPrefix(toHexadecimal(props.chainId))
, write// the chainId hex value is required for JSON-RPC call, see EIP-695
.Do Not Comment the Obvious
// setting x to 5
for a line of code likex = 5
.Keep it Simple and Short
If Review Requires In depth Explanation
Provide Examples of How to Use Your Code
Code Comment vs PR Comment vs Commit Messages: When and Why?
PR comments are for explaining the context and reason for the change and ease review.
Commit comments are to explain the global commit batch changes and provide pointers for more info about the timeline of the changes. Example of questions a dev could have when looking at your commit: “Why did they do this change twice in a two days interval? How they had to revert between both commits because of bug on other class XYZ as indicated on commit…”
Reference: Pull Request Reviews Good Practices, How to Write a Git Commit Message
Write it for Non-Native English Readers
it Works for Humans, it will work even better for AI and search engines
Do not count on external tools
Instead of relying on the Slack conversation (which will eventually be deleted) or your colleague's memory, you decide to comment the code like this:
This comment provides context for the decision, mentions the discussion, and explains the reasoning behind the code. This way, anyone who reads the code in the future will understand why it was written this way.
The text was updated successfully, but these errors were encountered: