Difference between revisions of "Comment (computer programming)"
Karl Jones (Talk | contribs) (Created page with "In computer programming, a '''comment''' is a programmer-readable annotation in the source code of a computer program. == Description == They are added with the...") |
Karl Jones (Talk | contribs) (→See also) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
They are added with the purpose of making the source code easier to understand, and are generally ignored by [[Compiler|compilers]] and [[Interpreter (computing)|interpreters]]. | They are added with the purpose of making the source code easier to understand, and are generally ignored by [[Compiler|compilers]] and [[Interpreter (computing)|interpreters]]. | ||
− | The [[Syntax (computer programming)|syntax]] of comments in various [[Programming | + | The [[Syntax (computer programming)|syntax]] of comments in various [[Programming language|programming languages]] varies considerably. |
As well as of direct use to any [[programmer]] reading the [[source code]], comments are sometimes processed in various ways to generate documentation external to the source code itself by [[Documentation generator|documentation generators]], or used for integration with source code management systems and other kinds of external programming tools. | As well as of direct use to any [[programmer]] reading the [[source code]], comments are sometimes processed in various ways to generate documentation external to the source code itself by [[Documentation generator|documentation generators]], or used for integration with source code management systems and other kinds of external programming tools. | ||
The flexibility provided by comments allows for a wide degree of variability, but formal conventions for their use are commonly part of programming style guides. | The flexibility provided by comments allows for a wide degree of variability, but formal conventions for their use are commonly part of programming style guides. | ||
+ | |||
+ | == Uses == | ||
+ | |||
+ | How best to make use of comments is subject to dispute; different commentators have offered varied and sometimes opposing viewpoints. There are many different ways of writing comments and many commentators who offer sometimes conflicting advice. | ||
+ | |||
+ | Comments can be used as a form of pseudocode to outline intention prior to writing the actual code. In this case it should explain the logic behind the code rather than the code itself. | ||
+ | |||
+ | Comments can be used to summarize code or to explain the programmer's intent. According to this school of thought, restating the code in plain English is considered superfluous; the need to re-explain code may be a sign that it is too complex and should be rewritten, or that the naming is bad. | ||
+ | |||
+ | Sometimes source code contains a novel or noteworthy solution to a specific problem. In such cases, comments may contain an explanation of the methodology. | ||
== See also == | == See also == | ||
+ | * [[CSS comment]] | ||
+ | * [[HTML comment]] | ||
* [[PHP comment]] | * [[PHP comment]] | ||
Latest revision as of 05:24, 29 September 2016
In computer programming, a comment is a programmer-readable annotation in the source code of a computer program.
Contents
Description
They are added with the purpose of making the source code easier to understand, and are generally ignored by compilers and interpreters.
The syntax of comments in various programming languages varies considerably.
As well as of direct use to any programmer reading the source code, comments are sometimes processed in various ways to generate documentation external to the source code itself by documentation generators, or used for integration with source code management systems and other kinds of external programming tools.
The flexibility provided by comments allows for a wide degree of variability, but formal conventions for their use are commonly part of programming style guides.
Uses
How best to make use of comments is subject to dispute; different commentators have offered varied and sometimes opposing viewpoints. There are many different ways of writing comments and many commentators who offer sometimes conflicting advice.
Comments can be used as a form of pseudocode to outline intention prior to writing the actual code. In this case it should explain the logic behind the code rather than the code itself.
Comments can be used to summarize code or to explain the programmer's intent. According to this school of thought, restating the code in plain English is considered superfluous; the need to re-explain code may be a sign that it is too complex and should be rewritten, or that the naming is bad.
Sometimes source code contains a novel or noteworthy solution to a specific problem. In such cases, comments may contain an explanation of the methodology.
See also
External links
- Comment (computer programming) @ Wikipedia