Comment (computer programming)

From Wiki @ Karl Jones dot com
Jump to: navigation, search

In computer programming, a comment is a programmer-readable annotation in the source code of a computer program.

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