Comment out
In computer programming, source code may be disabled by commenting out any given section of the code. This method is available in programming languages, markup languages, configuration files and other media that support comments. The term is also applied to any of various other means of temporarily disabling or removing source code from a computer program.[1]
Purpose
A programmer or author of code may use this approach when a subsection of code is redundant or obsolete, but is being left in the source to make the intent of the active code clearer, or when a piece of code is faulty and a temporary bypass is needed in order to debug another part of the code.
Problems with usage
Commenting out can be onerous in languages that do not have block comments, and has its own hazards in certain languages that do have block comments. For example, in C, the comment delimiters may not be nested, so /*/*Foo*/*/
is the comment /*Foo
, followed by the literal code characters */
, which can lead to bugs when a section of code containing block comments is commented out. In C, a conditional preprocessor directive should generally be used instead. Some languages, like Haskell, avoid this by allowing the nesting of block comments, so the example above (translated into Haskell) read {-{-Foo-}-}
and is actually the comment {-Foo-}
and no characters of code.
Notes and references
- ^ Source code may be disabled, for instance, with a conditional statement that is always false.