-
-
Notifications
You must be signed in to change notification settings - Fork 684
update comments concept docs
#3054
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| { | ||
| "blurb": "Comments are human-readable annotations on the code that make programs easier to understand by other programmers.", | ||
| "authors": ["nikimanoledaki"], | ||
| "contributors": [] | ||
| "blurb": "Go uses comments to annotate code and generate package documentation.", | ||
| "authors": [ | ||
| "nikimanoledaki" | ||
| ], | ||
| "contributors": [ | ||
| "BNAndras" | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,48 @@ | ||
| # Introduction | ||
|
|
||
| In the previous concept, we saw that there are two ways to write comments in Go: single-line comments that are preceded by `//`, and multiline comment blocks that are wrapped with `/*` and `*/`. | ||
| Comments let you leave notes in code without affecting how it runs. | ||
| Single-line comments start with `//`, and multiline comments are wrapped in `/*` and `*/`: | ||
|
|
||
| ```go | ||
| // This is a single-line comment. | ||
|
|
||
| /* | ||
| This is a | ||
| multiline comment. | ||
| */ | ||
| ``` | ||
|
|
||
| Comments serve different purposes depending on where they appear. | ||
|
|
||
| ## Code comments | ||
|
|
||
| Code comments explain why something is done, not what. | ||
| Use them when the reason behind a decision isn't obvious from the code: | ||
|
|
||
| ```go | ||
| results = results[1:] // skipping the header row | ||
| ``` | ||
|
|
||
| ## Doc comments | ||
|
|
||
| Doc comments sit directly before a declaration, with no blank line separating the comment from the declaration. | ||
| [`godoc`][godoc] parses them to generate package documentation. | ||
| A doc comment should be a complete sentence starting with the name of the identifier and ending with a period. | ||
|
|
||
| Package comments begin with the package name: | ||
|
|
||
| ```go | ||
| // Package kelvin provides tools to convert temperatures to and from Kelvin. | ||
| package kelvin | ||
| ``` | ||
|
|
||
| Function comments begin with the function name: | ||
|
|
||
| ```go | ||
| // CelsiusFreezingTemp returns an integer value equal to the temperature at which water freezes in degrees Celsius. | ||
| func CelsiusFreezingTemp() int { | ||
| return 0 | ||
| } | ||
| ``` | ||
|
|
||
| [godoc]: https://go.dev/blog/godoc |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.