Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.
Revision as of 08:02, 13 August 2025 by Dylan (talk | contribs) (link to single-line and multi-line pages specifically instead of generic C-style comment page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Comments are the way programmers explain parts of their code.

They act as guides to future maintainers as to how the codebase is structured.

What comments should do

edit edit source

Comments are very useful when:

  • You have a complicated piece of code and its function can be explained simply in a comment (often though, it makes more sense to create a function for this).
  • You've found that the current implementation is faster, and want to explain that to future maintainers
  • Credit code from other sources
  • Provide links to further reading on a concept
  • Use doc comments for documenting a function, struct field, etc.

What comments should NOT do

edit edit source
// this is a full-line C-style comment
int a = 5; // you can also place them at the end of a statement
/*
This is a multi-line comment
They start with a / then a * ...
... and end with a * then a /
*/

/* it's often convention to start each new line in
 * a multi-line comment with an asterisk (*) to
 * maintain formatting. */