guides:programstyle:comments
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| guides:programstyle:comments [2020/08/18 11:23] – [Comment Placement in Code] wikiadmin | guides:programstyle:comments [2022/08/02 11:59] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 104: | Line 104: | ||
| </ | </ | ||
| - | Finally, most comments | + | Use comments |
| + | < | ||
| + | // Get the noun from the user | ||
| + | noun = GetWord("a noun" | ||
| + | // Get the adjective from the user | ||
| + | adjective = GetWord(" | ||
| + | // Get the action verb from the user | ||
| + | actionVerb = GetWord(" | ||
| + | </code> | ||
| + | The code above is mostly self documenting due to identifier choice, so a single comment would be more appropriate | ||
| + | <code c++> | ||
| + | // Get the words from the user | ||
| + | noun = GetWord(" | ||
| + | adjective = GetWord(" | ||
| + | actionVerb = GetWord(" | ||
| + | </ | ||
| + | |||
| + | |||
| + | Finally, most comments in code should employ a c++ style line comment. | ||
| + | |||
| + | ==== Comment Contents ==== | ||
| + | |||
| + | Comments should describe the code, however comments should not repeat the code. | ||
| + | |||
| + | An acceptable example: | ||
| + | <code c++> | ||
| + | // use the Pythagorean theorem (a^2+b^2 = c^2) to find the length of the third size. | ||
| + | hypot = sqrt(sideA * sideA + sideB * sideB) | ||
| + | </ | ||
| + | |||
| + | An unacceptable example: | ||
| + | <code c++> | ||
| + | // c = sqrt(a*a + b*b) | ||
| + | hypot = sqrt(sideA * sideA + sideB * sideB); | ||
| + | </ | ||
| + | In the above example, the comment provides NO additional information. | ||
| + | |||
| + | |||
| + | In general, comments should support a knowledgeable programmer. | ||
guides/programstyle/comments.1597749817.txt.gz · Last modified: 2022/08/02 11:59 (external edit)