# Comment (computer programming)

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Comment_(computer_programming)
> Markdown URL: https://mediated.wiki/source/Comment_(computer_programming).md
> Source: https://en.wikipedia.org/wiki/Comment_(computer_programming)
> Source revision: 1356905822
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

Text in computer source code that is generally ignored by a compiler/interpreter

For comments in Wikipedia markup, see [Help:Wiki markup § Character formatting](https://en.wikipedia.org/wiki/Help:Wiki_markup#Character_formatting), and [WP:COMMENT](https://en.wikipedia.org/wiki/Wikipedia:COMMENT).

"/*" and "*/" redirect here. For their use in Wikipedia edit summaries, see [Help:Edit summary § Section editing](https://en.wikipedia.org/wiki/Help:Edit_summary#Section_editing).

[Java](/source/Java_(programming_language)) source code with block comments in red, line comments in green and program code in  blue.

In [computer programming](/source/Computer_programming), a **comment** is text embedded in [source code](/source/Source_code) that a translator ([compiler](/source/Compiler) or [interpreter](/source/Interpreter_(computing))) ignores. Generally, a comment is an [annotation](/source/Annotation) intended to make the code easier for a [programmer](/source/Programmer) to understand – often explaining an aspect that is not readily apparent in the program (non-comment) code.[1] For this article, *comment* refers to the same concept in a [programming language](/source/Programming_language), [markup language](/source/Markup_language), [configuration file](/source/Configuration_file) and any similar context.[2] Some [development tools](/source/Development_tool), other than a source code translator, do [parse](/source/Parse) comments to provide capabilities such as [API](/source/API) [document generation](/source/Documentation_generator), [static analysis](/source/Static_analysis), and [version control](/source/Version_control) integration. The [syntax of comments](/source/Comparison_of_programming_languages_(syntax)#Comments) varies by programming language yet there are repeating patterns in the syntax among languages as well as similar aspects related to comment content.

The flexibility supported by comments allows for a wide degree of content style variability. To promote uniformity, style conventions are commonly part of a [programming style](/source/Programming_style) guide. But, [best practices](/source/Best_practice) are disputed and contradictory.[3][4]

## Common attributes

Support for code comments is defined by each programming language. The features differ by language, but there are several common attributes that apply throughout.

Most languages support multi-line block (a.k.a. stream) and/or single line comments. A **block comment** is [delimited](/source/Delimiter#Bracket_delimiters) with text that marks the start and end of comment text. It can span multiple lines or occupy any part of a line. Some languages allow block comments to be recursively nested inside one another, but others do not.[5][6][7] A **line comment** ends at the end of the text line. In modern languages, a line comment starts with a delimiter but some older languages designate a column at which subsequent text is considered comment.[7] Many languages support both block and line comments – using different delimiters for each. For example, [C](/source/C_(programming_language)), [C++](/source/C%2B%2B) and their many derivatives support block comments delimited by /* and */ and line comments delimited by //. Other languages support only one type of comment.[7]

Comments can also be classified as either prologue or inline based on their position and content relative to program code. A **prologue comment** is a comment (or group of related comments) located near the top of an associated programming topic, such as before a symbol declaration or at the top of a file. An **inline comment** is a comment that is located on the same line as and to the right of program code to which it refers.[8] Both prologue and inline comments can be represented as either line or block comments. For example:

/*
 * prologue block comment
 */
bool foo() {
     return true; /* inline block comment */
}

//
// prologue line comment
//
bool bar() {
     return false; // inline line comment
}

## Examples of use

### Describe intent

Comments can explain the author's intent – *why* the code is as it is. Some contend that describing *what* the code does is superfluous. The need to explain the *what* is a sign that it is too complex and should be re-worked.

- "Don't document bad code – rewrite it."[9]

- "Good comments don't repeat the code or explain it. They clarify its intent. Comments should explain, at a higher level of abstraction than the code, what you're trying to do."[10]

### Highlight unusual practice

Comments may explain why a choice was made to write code that is counter to convention or best practice. For example:

' Second variable dim because of server errors produced when reuse form data.
' No documentation available on server behavior issue, so just coding around it.
vtx = server.mappath("local settings")

The example below explains why an [insertion sort](/source/Insertion_sort) was chosen instead of a [quicksort](/source/Quicksort), as the former is, in theory, slower than the latter.

 list = [f (b), f (b), f (c), f (d), f (a), ...];
 // Need a stable sort. Besides, the performance really does not matter.
 insertion_sort (list);

### Describe algorithm

Comments can describe an algorithm as [pseudocode](/source/Pseudocode). This could be done before writing the code as a first draft. If left in the code, it can simplify [code review](/source/Code_review) by allowing comparison of the resulting code with the intended logic. For example:

/* loop backwards through all elements returned by the server
(they should be processed chronologically)*/
for (i = (numElementsReturned - 0); i >= 1; i--) {
    /* process each element's data */
    updatePattern(i, returnedElements[i]);
}

Sometimes code contains a novel or noteworthy solution that warrants an explanatory comment. Such explanations might be lengthy and include diagrams and formal mathematical proofs. This may describe what the code does rather than intent, but may be useful for maintaining the code. This might apply for highly specialized problem domains or rarely used optimizations, constructs or function-calls.[11]

### References

When some aspect of the code is based on information in an external reference, comments link to the reference. For example as a URL or book name and page number.

### Comment out

This section does not cite any sources. Please help improve this section by adding citations to reliable sources. Unsourced material may be challenged and removed. (April 2026) (Learn how and when to remove this message)

A common developer practice is to **comment out** one or more lines of code. The programmer adds comment syntax that converts program code into comments so that what was executable code will no longer be executed at runtime. Sometimes this technique is used to find the cause of a bug. By systematically commenting out and running parts of the program, the offending source code can be located.

Many IDEs support adding and removing comments with convenient [user interface](/source/User_interface) actions such as a [keyboard shortcut](/source/Keyboard_shortcut).

### Store metadata

Comments can store [metadata](/source/Metadata) about the code. Common metadata includes the name of the original author and subsequent maintainers, dates when first written and modified, link to development and user documentation, and legal information such as [copyright](/source/Copyright) and [software license](/source/Software_license). Rarely, [text-encoded, binary data](/source/Binary-to-text_encoding) can be included.

Some [programming tools](/source/Programming_tools) write metadata into the code as comments.[12] For example, a [version control](/source/Version_control) tool might write metadata such as author, date and version number into each file when it's committed to the repository.[13]

### Integrate with development tools

Sometimes information stored in comments is used by development tools other than the translator – the primary tool that consumes the code. This information may include metadata (often used by a documentation generator) or tool configuration.

Some [source code editors](/source/Source_code_editor) support configuration via metadata in comments.[14] One particular example is the *modeline* feature of [Vim](/source/Vim_(text_editor)) which configures tab character handling. For example:

# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

### Support documentation generation

An [API](/source/API) [documentation generator](/source/Documentation_generator) parses information from a codebase to generate API documentation. Many support reading information from comments, often parsing metadata, to control the content and formatting of the resulting document.

Although some claim that API documentation can be higher quality when written in a more traditional and manual way, some claim that storing documentation information in code comments simplifies the documenting process, as well as increases the likelihood that the documentation will be kept up to date.[15] Examples include [Javadoc](/source/Javadoc), Ddoc, [Doxygen](/source/Doxygen), [Visual Expert](/source/Visual_Expert) and [PHPDoc](/source/PHPDoc). Forms of [docstring](/source/Docstring) are supported by [Python](/source/Python_(programming_language)), [Lisp](/source/Lisp_(programming_language)), [Elixir](/source/Elixir_(programming_language)), and [Clojure](/source/Clojure).[16] [C#](/source/C_Sharp_(programming_language)), [F#](/source/F_Sharp_(programming_language)) and [Visual Basic .NET](/source/Visual_Basic_.NET) implement a similar feature called "XML Comments" which are read by [IntelliSense](/source/IntelliSense) from the compiled [.NET](/source/.NET) assembly.[17]

### Visualization

An [ASCII art](/source/ASCII_art) [visualization](/source/Data_and_information_visualization) such as a [logo](/source/Logo), diagram, or [flowchart](/source/Flowchart) can be included in a comment.[18]

The following code fragment depicts the process flow of a [system administration](/source/System_administration) script ([Windows script file](/source/Windows_Script_File)). Although a section marking the code appears as a comment, the diagram is in an [XML](/source/XML) [CDATA](/source/CDATA) section, which is technically not a comment, but serves the same purpose here.[19] Although this diagram could be in a comment, the example illustrates one instance where the programmer opted not to use a comment as a way of including resources in source code.[19]

<!-- begin: wsf_resource_nodes -->
<resource id="ProcessDiagram000">
<![CDATA[
 HostApp (Main_process)
    |
    V
script.wsf (app_cmd) --> ClientApp (async_run, batch_process)
                |
                |
                V
         mru.ini (mru_history)
]]>
</resource>

### Document development process

Sometimes, comments describe development processes related to the code. For example, comments might describe how to [build](/source/Software_build) the code or how to submit changes to the [software maintainer](/source/Software_maintainer).

### Extend language syntax

Occasionally, code that is formatted as a comment is overloaded to convey additional information to the translator, such as conditional comments. As such, syntax that generally indicates a comment can actually represent program code, not comment code. Such syntax may be a practical way to maintain compatibility while adding additional functionality, but some regard such a solution as a [kludge](/source/Kludge).[20]

Other examples include interpreter [directives](/source/Directive_(programming)):

- The Unix "[shebang](/source/Shebang_(Unix))" – #! – used on the first line of a script to point to the interpreter to be used.

- "Magic comments" identifying the encoding a source file is using,[21] e.g. Python's PEP 263.[22]

The script below for a [Unix-like](/source/Unix-like) system shows both of these uses:

#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
print("Testing")

The [gcc](/source/GNU_Compiler_Collection) compiler (since 2017) looks for a comment in a [switch statement](/source/Switch_statement) if a case falls-thru to the next case. If an explicit indication of fall-thru is not found, then the compiler issues a warning about a possible coding problem. Inserting such a comment about fall-thru is a long standing convention, and the compiler has codified the practice.[23] For example:

switch (command) {
    case CMD_SHOW_HELP_AND_EXIT:
      do_show_help();
      /* Fall thru */
    case CMD_EXIT:
      do_exit();
      break;
  }

### Relieve stress

To relieve stress or attempt humor, sometimes programmers add comments about the quality of the code, tools, competitors, employers, working conditions, or other arguably unprofessional topics – sometimes using [profanity](/source/Profanity).[24][25]

## Normative views

There are various normative views and long-standing opinions regarding the proper use of comments in source code.[26][27] Some of these are informal and based on personal preference, while others are published or promulgated as formal guidelines for a particular community.[28]

### Need for comments

Experts have varying viewpoints on whether, and when, comments are appropriate in source code.[9][29] Some assert that source code should be written with few comments, on the basis that the source code should be self-explanatory or [self-documenting](/source/Self-documenting).[9] Others suggest code should be extensively commented (it is not uncommon for over 50% of the non-[whitespace](/source/Whitespace_(computer_science)) characters in source code to be contained within comments).[30][31]

In between these views is the assertion that comments are neither beneficial nor harmful by themselves, and what matters is that they are correct and kept in sync with the source code, and omitted if they are superfluous, excessive, difficult to maintain or otherwise unhelpful.[32][33]

Comments are sometimes used to document contracts in the [design by contract](/source/Design_by_contract) approach to programming.

### Level of detail

Depending on the intended audience of the code and other considerations, the level of detail and description may vary considerably.

For example, the following Java comment would be suitable in an introductory text designed to teach beginning programming:

String s = "Wikipedia"; /* Assigns the value "Wikipedia" to the variable s. */

This level of detail, however, would not be appropriate in the context of production code, or other situations involving experienced developers. Such rudimentary descriptions are inconsistent with the guideline: "Good comments ... clarify intent."[10] Further, for professional coding environments, the level of detail is ordinarily well defined to meet a specific performance requirement defined by business operations.[31]

## Styles

As free-form text, comments can be styled in a wide variety of ways. Many prefer a style that is consistent, non-obstructive, easy to modify, and difficult to break. As some claim that a level of consistency is valuable and worthwhile, a consistent commenting style is sometimes agreed upon before a project starts or emerges as development progresses.[34]

The following C code fragments show some of the diversity in block comment style:

/*
     This is the comment body.
*/

/*****************************
 *                           *
 * This is the comment body. *
 *                           *
 *****************************/

Factors such as personal preference, flexibility of programming tools can influence the commenting style used. For example, the first might be preferred by programmers who use a [source code editor](/source/Source_code_editor) that does not automatically format a comment as shown in the second example.

Software consultant and technology commentator [Allen Holub](/source/Allen_Holub)[35] advocates aligning the left edges of comments:[36]

 /* This is the style recommended by Holub for C and C++.
  * It is demonstrated in ''Enough Rope'', in rule 29.
  */

 /* This is another way to do it, also in C.
 ** It is easier to do in editors that do not automatically indent the second
 ** through last lines of the comment one space from the first.
 ** It is also used in Holub's book, in rule 31.
 */

In many languages, a line comment can follow program code such that the comment is *inline* and generally describes the code to the left of it. For example, in this Perl:

print $s . "\n";     # Add a newline character after printing

If a language supports both line and block comments, programming teams may decide upon a convention of when to use which. For example, line comments only for minor comments, and block comments to for higher-level abstractions.

## Tag

Some comments are categorized with a prefix – a [tag](/source/Tag_(metadata)), codetag[37][38] or token.[39] Some editors [highlight](/source/Syntax_highlighting) a comment based on its tag.

Commonly used tags include:

- BUG, DEBUG — identifies a known [bug](/source/Software_bug), perhaps implying it should be fixed

- FIXME — implies that there is work to do to fix a bug

- HACK, BODGE, KLUDGE — marks a solution that might be considered low quality

- TODO — describes some work to do

- NOTE — relatively general information

- UNDONE — a reversal or "roll back" of previous code

For example:

int current_stock_price() {
    return 100;
    // TODO implement API call to fetch actual live price
}

## Syntax examples

Syntax for comments varies by programming language. There are common patterns used by multiple languages while also a wide range of syntax among the languages in general. To limit the length of this section, some examples are grouped by languages with the same or very similar syntax. Others are for particular languages that have less common syntax.

### Curly brace languages

Many of the [curly brace languages](/source/Curly_brace_language) such as C, C++ and their many derivatives delimit a line comment with // and a block comment with /* and */. Originally, C lacked the line comment, but it was added in [C99](/source/C99). Notable languages include: C, C++, [C#](/source/C_Sharp_(programming_language)), [D](/source/D_(programming_language)), [Java](/source/Java_(programming_language)), [JavaScript](/source/JavaScript) and [Swift](/source/Swift_(programming_language)). For example:

/*
 * Check if over maximum process limit, but be sure to exclude root.
 * This is needed to make it possible for login to set per-user
 * process limit to something lower than processes root is running.
 */
bool isOverMaximumProcessLimit() {
     // TODO implement
}

Some languages, including D[40] and Swift[41], allow block comments to be nested while other do not, including C and C++.

An example of nested blocks in D:

// line comment
/*
    block comment
*/
/+ start of outer block
  /+ inner block +/
    end of outer block +/

An example of nested blocks in Swift:

/* This is the start of the outer comment.
    /* This is the nested comment. */
This is the end of the outer comment. */

### Scripting

A pattern in many [scripting languages](/source/Scripting_language) is to delimit a line comment with #. Support for a block comment varies. Notable languages include: [Bash](/source/Bash_(Unix_shell)), [Raku](/source/Raku_(programming_language)), [Ruby](/source/Ruby_(programming_language)), [Perl](/source/Perl), [PowerShell](/source/Windows_PowerShell), [Python](/source/Python_(programming_language)) and [R](/source/R_(programming_language)).

An example in R:

# This is a comment
print("This is not a comment")  # This is another comment

#### Block in Ruby

A block comment is delimited by =begin and =end that start a line. For example:

puts "not a comment"
# this is a comment
puts "not a comment"
=begin
whatever goes in these lines
is just for the human reader
=end
puts "not a comment"

#### Block in Perl

Instead of a regular block commenting construct, Perl uses [literate programming](/source/Literate_programming) [plain old documentation (POD)](/source/Plain_Old_Documentation) markup.[42] For example:[43]

=item Pod::List-E<gt>new()
Create a new list object. Properties may be specified through a hash
reference like this:
  my $list = Pod::List->new({ -start => $., -indent => 4 });
=cut
sub new {
    ...
}

Raku (previously called Perl 6) uses the same line comments and POD comments as [Perl](/source/Perl), but adds a configurable block comment type: "multi-line / embedded comments".[44] It starts with #` and then an opening bracket character and ends with the matching closing bracket character.[44] For example:

#`{{ "commenting out" this version
toggle-case(Str:D $s)
Toggles the case of each character in a string:
  my Str $toggled-string = toggle-case("mY NAME IS mICHAEL!");
}}
sub toggle-case(Str:D $s) #`( this version of parens is used now ){
    ...
}

#### Block in PowerShell

PowerShell supports a block comment delimited by <# and #>. For example:

# Single line comment
<# Multi
   Line
   Comment #>

#### Block in Python

Although Python does not provide for block comments[45] a bare [string literal](/source/String_literal) represented by a triple-quoted string is often used for this purpose.[46][45] In the examples below, the triple double-quoted strings act like comments, but are also treated as [docstrings](/source/Docstring):

"""
At the top of a file, this is the module docstring
"""

class MyClass:
    """Class docstring"""

    def my_method(self):
        """Method docstring"""

### Browser markup

Markup languages in general vary in comment syntax, but some of the notable internet markup formats such as [HTML](/source/HTML) and [XML](/source/XML) delimit a block comment with <!-- and --> and provide no line comment support. An example in XML:

<!-- select the context here -->
<param name="context" value="public" />

For compatibility with [SGML](/source/SGML), double-hyphen (--) is not allowed inside comments.

[ColdFusion](/source/ColdFusion) provides syntax similar to the [HTML comment](/source/HTML_comment), but uses three dashes instead of two. CodeFusion allows for nested block comments.

#### Block in Haskell

In Haskell, a block comment is delimited by {- and -}. For example:

{- this is a comment
on more lines -}
-- and this is a comment on one line
putStrLn "Wikipedia"  -- this is another comment

Haskell also provides a [literate programming](/source/Literate_programming) method of commenting known as "Bird Style".[47] Lines starting with > are interpreted as code and everything else is considered a comment. One additional requirement is a blank line before and after the code block:

In Bird-style you have to leave a blank before the code.

> fact :: Integer -> Integer
> fact 0 = 1
> fact (n+1) = (n+1) * fact n

And you have to leave a blank line after the code as well.

Literate programming can also be accomplished via [LaTeX](/source/LaTeX). Example of a definition:

\usepackage{verbatim}
\newenvironment{code}{\verbatim}{\endverbatim}

Used as follows:

% the LaTeX source file
The \verb|fact n| function call computes $n!$ if $n\ge 0$, here is a definition:\\
\begin{code}
fact :: Integer -> Integer
fact 0 = 1
fact (n+1) = (n+1) * fact n
\end{code}
Here more explanation using \LaTeX{} markup

#### Block in Lua

Lua supports block comments delimited by --[[ and ]][48] For example:

--[[A multi-line
long comment
]]

#### Block in SQL

In some variants of SQL, the curly brace language block comment (/**/) is supported. Variants include: [Transact-SQL](/source/Transact-SQL), [MySQL](/source/MySQL), [SQLite](/source/SQLite), [PostgreSQL](/source/PostgreSQL), and [Oracle](/source/Oracle_Database).[49][50][51][52][53]

MySQL also supports a line comment delimited by #.

### Less common syntax

#### APL

[APL](/source/APL_(programming_language)) uses ⍝ ("lamp") for a line comment. For example:

⍝ Now add the numbers:
c←a+b ⍝ addition

In dialects that have the ⊣ ("left") and ⊢ ("right") primitives, comments can often be *inside* or separate statements, in the form of ignored strings:

d←2×c ⊣'where'⊢ c←a+ 'bound'⊢ b

#### AppleScript

[AppleScript](/source/AppleScript) supports both line and block comments. For example:

# line comment (in later versions)
(*
This program displays a greeting.
*)
on greet(myGreeting)
     display dialog myGreeting & " world!"
end greet

-- Show the greeting
greet("Hello")

#### BASIC

Early versions of [BASIC](/source/BASIC) used REM (short for remark) for a line comment.

10 REM This BASIC program shows the use of the PRINT and GOTO Statements.
15 REM It fills the screen with the phrase "HELLO"
20 PRINT "HELLO"
30 GOTO 20

In later variations, including [Quick Basic](/source/Quick_Basic), [Q Basic](/source/Q_Basic), [Visual Basic](/source/Visual_Basic) (VB), [VB.NET](/source/Visual_Basic_.NET), [VBScript](/source/VBScript), [FreeBASIC](/source/FreeBASIC) and [Gambas](/source/Gambas), a line comment is delimited with ' (apostrophe). An example in VB.NET:

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        ' new style line comment
        rem old style line comment still supported
        MessageBox.Show("Hello, World") ' show dialog with a greeting
    End Sub
End Class

#### Cisco IOS and IOS-XE configuration

The [exclamation point](/source/Exclamation_point) (**!**) may be used to mark comments in a Cisco router's configuration mode, however such comments are *not* saved to [non-volatile memory](/source/Non-volatile_memory) (which contains the startup-config), nor are they displayed by the "show run" command.[54][55]

It is possible to insert [human-readable](/source/Human-readable) content that is actually part of the configuration, and may be saved to the [NVRAM](/source/NVRAM) startup-config via:

- The "description" command, used to add a description to the configuration of an interface or of a [BGP](/source/BGP) neighbor

- The "name" parameter, to add a remark to a static route

- The "remark" command in access lists

! Paste the text below to reroute traffic manually
config t
int gi0/2
no shut
ip route 0.0.0.0 0.0.0.0 gi0/2 name ISP2
no ip route 0.0.0.0 0.0.0.0 gi0/1 name ISP1
int gi0/1
shut
exit

#### Fortran

The following fixed-form [Fortran](/source/Fortran) code fragment shows that comment syntax is column-oriented. A letter C in the first column causes the entire line to be treated as a comment. In [Fortran 77](/source/Fortran_77), an asterisk in column 1 also indicates a comment.

C
C Lines beginning with 'C' in the first (a.k.a. comment) column are comments
C
      WRITE (6,610)
  610 FORMAT(12H HELLO WORLD)
      END

The following [Fortran 90](/source/Fortran) code fragment shows a more modern line comment syntax: text following !.

! A comment
program comment_test
    print '(A)', 'Hello world' ! also a comment
end program

Free-form Fortran, also introduced with Fortran 90, only supports this latter style of comment.

Although not a part of the Fortran Standard, many Fortran compilers offer an optional C-like [preprocessor](/source/Preprocessor) pass. This can be used to provide block comments:

#if 0
  This is a block comment spanning
  multiple lines.
#endif
program comment_test
    print '(A)', 'Hello world' ! also a comment
end program

#### MATLAB

In [MATLAB](/source/MATLAB)'s programming language, the '%' character indicates a single-line comment. Multi line comments are also available via %{ and %} brackets and can be nested, e.g.

% These are the derivatives for each term
d = [0 -1 0];

%{
  %{
    (Example of a nested comment, indentation is for cosmetics (and ignored).)
  %}
  We form the sequence, following the Taylor formula.
  Note that we're operating on a vector.
%}
seq = d .* (x - c).^n ./(factorial(n))

% We add-up to get the Taylor approximation
approx = sum(seq)

#### Nim

[Nim](/source/Nim_(programming_language)) delimits a line comment with # and block comments with #[ and ]#. Block comments can be nested.

Nim also has documentation comments that use mixed [Markdown](/source/Markdown) and [ReStructuredText](/source/ReStructuredText) markups. A line documentation comment uses '##' and a block documentation comment uses '##[' and ']##'. The compiler can generate [HTML](/source/HTML), [LaTeX](/source/LaTeX) and [JSON](/source/JSON) documentation from the documentation comments. Documentation comments are part of the [abstract syntax tree](/source/Abstract_syntax_tree) and can be extracted using macros.[56]

## Documentation of the module *ReSTructuredText* and **MarkDown**
# This is a comment, but it is not a documentation comment.

type Kitten = object  ## Documentation of type
  age: int  ## Documentation of field

proc purr(self: Kitten) =
  ## Documentation of function
  echo "Purr Purr"  # This is a comment, but it is not a documentation comment.

# This is a comment, but it is not a documentation comment.

#### OCaml

[OCaml](/source/OCaml) supports nestable comments. For example:

codeLine(* comment level 1(*comment level 2*)*)

#### Pascal, Delphi

In [Pascal](/source/Pascal_(programming_language)) and [Delphi](/source/Delphi_(software)), a block comment is delimited by { and }, and as an alternative for computers that do not support these characters, (* and *) are also supported. A line comment is delimited by \\.[57] In [Niklaus Wirth](/source/Niklaus_Wirth)'s more modern family of languages (including [Modula-2](/source/Modula-2) and [Oberon](/source/Oberon_(programming_language))), comments are delimited by (* and *).[58][59] Comments can be nested. For example:

(* test diagonals *)
columnDifference := testColumn - column;
if (row + columnDifference = testRow) or
    .......

#### PHP

Comments in [PHP](/source/PHP) can be either curly brace style (both line and block), or line delimited with #l. Blocks cannot be nested. Starting in PHP 8, a # only means comment if it's not immediately followed by [. Otherwise, it delimits an attribute, which continues till the next ]. For example:

/**
 * This class contains a sample documentation.
 * @author Unknown
 */
#[Attribute]
class MyAttribute {
    const VALUE = 'value';
    // C++ style line comment
    private $value;
    # script style line comment
    public function __construct($value = null) {
        $this->value = $value;
    }
}

### Double dash

A relatively loose collection of languages use -- for a single line comment. Notable languages include: [Ada](/source/Ada_(programming_language)), [Eiffel](/source/Eiffel_(programming_language)), [Haskell](/source/Haskell_(programming_language)), [Lua](/source/Lua_(programming_language)), [SQL](/source/SQL) and [VHDL](/source/VHDL). Block comment support varies. An example in Ada:

-- the air traffic controller task takes requests for takeoff and landing
task type Controller (My_Runway: Runway_Access) is
   -- task entries for synchronous message passing
   entry Request_Takeoff (ID: in Airplane_ID; Takeoff: out Runway_Access);
   entry Request_Approach(ID: in Airplane_ID; Approach: out Runway_Access);
end Controller;

## Security issues

In [interpreted languages](/source/Interpreted_language), depending on the operating system's capabilities and the administrator's choices, the entire source code, including the comments, may be viewable to the program's [end user](/source/End_user). This may present a security [vulnerability](/source/Vulnerability_(computing)), when comments contain secrets or when secret sections of code are merely commented out.[60]

## See also

- [Comparison of programming languages (syntax)#Comments](/source/Comparison_of_programming_languages_(syntax)#Comments)

## Notes and references

1. **[^](#cite_ref-PennyGrubb000_1-0)** Penny Grubb, Armstrong Takang (2003). *Software Maintenance: Concepts and Practice*. World Scientific. pp. 7, plese start120–121. [ISBN](/source/ISBN_(identifier)) [978-981-238-426-3](https://en.wikipedia.org/wiki/Special:BookSources/978-981-238-426-3).

1. **[^](#cite_ref-2)** Ganguli, Madhushree (2002). *Making Use of Jsp*. New York: Wiley. [ISBN](/source/ISBN_(identifier)) [978-0-471-21974-3](https://en.wikipedia.org/wiki/Special:BookSources/978-0-471-21974-3)., Hewitt, Eben (2003). *Java for Coldfusion Developers*. Upper Saddle River: Pearson Education. [ISBN](/source/ISBN_(identifier)) [978-0-13-046180-3](https://en.wikipedia.org/wiki/Special:BookSources/978-0-13-046180-3).

1. **[^](#cite_ref-Dietrich000_3-0)** W. R., Dietrich (2003). *Applied Pattern Recognition: Algorithms and Implementation in C++*. Springer. [ISBN](/source/ISBN_(identifier)) [978-3-528-35558-6](https://en.wikipedia.org/wiki/Special:BookSources/978-3-528-35558-6). offers viewpoints on proper use of comments in source code. p. 66.

1. **[^](#cite_ref-Keyes000_4-0)** Keyes, Jessica (2003). *Software Engineering Handbook*. CRC Press. [ISBN](/source/ISBN_(identifier)) [978-0-8493-1479-7](https://en.wikipedia.org/wiki/Special:BookSources/978-0-8493-1479-7). discusses comments and the "Science of Documentation" p. 256.

1. **[^](#cite_ref-Higham000_5-0)** Higham, Desmond (2005). *MATLAB Guide*. SIAM. [ISBN](/source/ISBN_(identifier)) [978-0-89871-578-1](https://en.wikipedia.org/wiki/Special:BookSources/978-0-89871-578-1).

1. **[^](#cite_ref-Vermeulen000_6-0)** Vermeulen, Al (2000). [*The Elements of Java Style*](https://archive.org/details/elementsofjavast00verm). Cambridge University Press. [ISBN](/source/ISBN_(identifier)) [978-0-521-77768-1](https://en.wikipedia.org/wiki/Special:BookSources/978-0-521-77768-1).

1. ^ [***a***](#cite_ref-javadude000_7-0) [***b***](#cite_ref-javadude000_7-1) [***c***](#cite_ref-javadude000_7-2) ["Using the right comment in Java"](http://javadude.com/articles/comments.html). 2000-03-04. Retrieved 2007-07-24.

1. **[^](#cite_ref-JBDixit000_8-0)** Dixit, J.B. (2003). *Computer Fundamentals and Programming in C*. Laxmi Publications. [ISBN](/source/ISBN_(identifier)) [978-81-7008-882-0](https://en.wikipedia.org/wiki/Special:BookSources/978-81-7008-882-0).

1. ^ [***a***](#cite_ref-BadComment000_9-0) [***b***](#cite_ref-BadComment000_9-1) [***c***](#cite_ref-BadComment000_9-2) *[The Elements of Programming Style](/source/The_Elements_of_Programming_Style_(book))*, [Kernighan](/source/Brian_Kernighan) & [Plauger](/source/P._J._Plauger)

1. ^ [***a***](#cite_ref-GoodComment000_10-0) [***b***](#cite_ref-GoodComment000_10-1) *[Code Complete](/source/Code_Complete)*, [McConnell](/source/Steve_McConnell)

1. **[^](#cite_ref-AlgoComments_11-0)** Spinellis, Diomidis (2003). *Code reading: The Open Source Perspective*. Addison-Wesley. [ISBN](/source/ISBN_(identifier)) [978-0-201-79940-8](https://en.wikipedia.org/wiki/Special:BookSources/978-0-201-79940-8).

1. **[^](#cite_ref-12)** See e.g., Wynne-Powell, Rod (2008). [*Mac OS X for Photographers: Optimized Image Workflow for the Mac User*](https://archive.org/details/macosxforphotogr0000wynn). Oxford: Focal Press. p. 243. [ISBN](/source/ISBN_(identifier)) [978-0-240-52027-8](https://en.wikipedia.org/wiki/Special:BookSources/978-0-240-52027-8).

1. **[^](#cite_ref-13)** See e.g., Berlin, Daniel (2006). *Practical Subversion, Second Edition*. Berkeley: APress. p. 168. [ISBN](/source/ISBN_(identifier)) [978-1-59059-753-8](https://en.wikipedia.org/wiki/Special:BookSources/978-1-59059-753-8).

1. **[^](#cite_ref-14)** Lamb, Linda (1998). [*Learning the VI Editor*](https://archive.org/details/learningvieditor00lamb). Sebastopol: O'Reilly & Associates. [ISBN](/source/ISBN_(identifier)) [978-1-56592-426-0](https://en.wikipedia.org/wiki/Special:BookSources/978-1-56592-426-0).

1. **[^](#cite_ref-Ambler000_15-0)** Ambler, Scott (2004). *The Object Primer: Agile Model-Driven Development with UML 2.0*. Cambridge University Press. [ISBN](/source/ISBN_(identifier)) [978-1-397-80521-8](https://en.wikipedia.org/wiki/Special:BookSources/978-1-397-80521-8).

1. **[^](#cite_ref-16)** [Function definition with docstring in Clojure](https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/defn)

1. **[^](#cite_ref-17)** Murach. *C# 2005*. p. 56.

1. **[^](#cite_ref-asciiart000_18-0)** ["CodePlotter 1.6 – Add and edit diagrams in your code with this 'Visio-like' tool"](https://web.archive.org/web/20070714092702/http://www.codeproject.com/macro/codeplotter.asp). Archived from [the original](http://www.codeproject.com/macro/codeplotter.asp) on 2007-07-14. Retrieved 2007-07-24.

1. ^ [***a***](#cite_ref-Niederst000_19-0) [***b***](#cite_ref-Niederst000_19-1) Niederst, Jennifer (2006). *Web Design in a Nutshell: A Desktop Quick Reference*. O'Reilly. [ISBN](/source/ISBN_(identifier)) [978-0-596-00987-8](https://en.wikipedia.org/wiki/Special:BookSources/978-0-596-00987-8). Sometimes the difference between a "comment" and other syntax elements of a programming or markup language entails subtle nuances. Niederst indicates one such situation by stating: "Unfortunately, XML software thinks of comments as unimportant information and may simply remove the comments from a document before processing it. To avoid this problem, use an XML CDATA section instead."

1. **[^](#cite_ref-20)** [c2: HotComments](https://wiki.c2.com/?HotComments)

1. **[^](#cite_ref-21)** ["class Encoding"](https://docs.ruby-lang.org/en/2.4.0/Encoding.html). *Ruby*. ruby-lang.org. Retrieved 5 December 2018.

1. **[^](#cite_ref-22)** ["PEP 263 – Defining Python Source Code Encodings"](https://www.python.org/dev/peps/pep-0263/). Python.org. Retrieved 5 December 2018.

1. **[^](#cite_ref-23)** Polacek, Marek (2017-03-10). ["-Wimplicit-fallthrough in GCC 7"](https://developers.redhat.com/blog/2017/03/10/wimplicit-fallthrough-in-gcc-7/). *Red Hat Developer*. Red Hat. Retrieved 10 February 2019.

1. **[^](#cite_ref-24)** Lisa Eadicicco (27 March 2014). ["Microsoft Programmers Hid A Bunch Of Profanity In Early Software Code"](https://www.businessinsider.com/microsoft-hidden-messages-in-word-and-ms-dos-2014-3?r=US&IR=T). *[Business Insider Australia](/source/Business_Insider_Australia)*. [Archived](https://web.archive.org/web/20161229170544/http://www.businessinsider.com.au/microsoft-hidden-messages-in-word-and-ms-dos-2014-3?r=US&IR=T) from the original on 29 December 2016.

1. **[^](#cite_ref-SwearWords_25-0)** (see e.g., [Linux Swear Count](http://www.vidarholen.net/contents/wordcount/)).

1. **[^](#cite_ref-26)** Goodliffe, Pete (2006). *Code Craft*. San Francisco: No Starch Press. [ISBN](/source/ISBN_(identifier)) [978-1-59327-119-0](https://en.wikipedia.org/wiki/Special:BookSources/978-1-59327-119-0).

1. **[^](#cite_ref-27)** Smith, T. (1991). *Intermediate Programming Principles and Techniques Using Pascal*. Belmont: West Pub. Co. [ISBN](/source/ISBN_(identifier)) [978-0-314-66314-6](https://en.wikipedia.org/wiki/Special:BookSources/978-0-314-66314-6).

1. **[^](#cite_ref-28)** See e.g., Koletzke, Peter (2000). *Oracle Developer Advanced Forms & Reports*. Berkeley: Osborne/McGraw-Hill. [ISBN](/source/ISBN_(identifier)) [978-0-07-212048-6](https://en.wikipedia.org/wiki/Special:BookSources/978-0-07-212048-6). page 65.

1. **[^](#cite_ref-BadComments001_29-0)** ["Worst Practice - Bad Comments"](http://www.sqlservercentral.com/columnists/awarren/worstpracticebadcomments.asp). Retrieved 2007-07-24.

1. **[^](#cite_ref-Morelli000_30-0)** Morelli, Ralph (2006). *Java, Java, Java: object-oriented problem solving*. Prentice Hall College. [ISBN](/source/ISBN_(identifier)) [978-0-13-147434-5](https://en.wikipedia.org/wiki/Special:BookSources/978-0-13-147434-5).

1. ^ [***a***](#cite_ref-Javadoc000_31-0) [***b***](#cite_ref-Javadoc000_31-1) ["How to Write Doc Comments for the Javadoc Tool"](http://java.sun.com/j2se/javadoc/writingdoccomments/). Retrieved 2007-07-24. Javadoc guidelines specify that comments are crucial to the platform. Further, the appropriate level of detail is fairly well-defined: "We spend time and effort focused on specifying boundary conditions, argument ranges and corner cases rather than defining common programming terms, writing conceptual overviews, and including examples for developers."

1. **[^](#cite_ref-techniques001_32-0)** Yourdon, Edward (2007). *Techniques of Program Structure and Design*. University of Michigan. 013901702X.Non-existent comments can make it difficult to comprehend code, but comments may be detrimental if they are obsolete, redundant, incorrect or otherwise make it more difficult to comprehend the intended purpose for the source code.

1. **[^](#cite_ref-CmmtPhilosophy_33-0)** Dewhurst, Stephen C (2002). *C++ Gotchas: Avoiding Common Problems in Coding and Design*. Addison-Wesley Professional. [ISBN](/source/ISBN_(identifier)) [978-0-321-12518-7](https://en.wikipedia.org/wiki/Special:BookSources/978-0-321-12518-7).

1. **[^](#cite_ref-gnome000_34-0)** ["Coding Style"](https://web.archive.org/web/20070808173421/http://developer.gnome.org/doc/guides/programming-guidelines/code-style.html). Archived from [the original](http://developer.gnome.org/doc/guides/programming-guidelines/code-style.html) on 2007-08-08. Retrieved 2007-07-24.

1. **[^](#cite_ref-Holub000_35-0)** ["Allen Holub"](https://web.archive.org/web/20070720153845/http://www.holub.com/company/allen_holub.html). Archived from [the original](http://www.holub.com/company/allen_holub.html) on 2007-07-20. Retrieved 2007-07-24.

1. **[^](#cite_ref-Holub001_36-0)** Allen Holub, *Enough Rope to Shoot Yourself in the Foot*, [ISBN](/source/ISBN_(identifier)) [0-07-029689-8](https://en.wikipedia.org/wiki/Special:BookSources/0-07-029689-8), 1995, McGraw-Hill

1. **[^](#cite_ref-37)** ["PEP 0350 – Codetags"](https://www.python.org/dev/peps/pep-0350/#what-are-codetags), Python Software Foundation

1. **[^](#cite_ref-38)** ["Never Forget Anything Before, After and While Coding"](https://medium.com/@eido.askayo/never-forget-anything-before-after-and-while-coding-98d187ae4cf1), Using "codetag" comments as productive remainders

1. **[^](#cite_ref-39)** ["Using the Task List"](https://msdn.microsoft.com/en-us/library/txtwdysk.aspx#tokenscomments), msdn.microsoft.com

1. **[^](#cite_ref-40)** ["Lexical"](https://dlang.org/spec/lex.html#comment). *D Programming Language*. Retrieved 2025-11-17.

1. **[^](#cite_ref-41)** ["Lexical Structure | Documentation"](https://docs.swift.org/swift-book/documentation/the-swift-programming-language/lexicalstructure/#Whitespace-and-Comments). *docs.swift.org*. Retrieved 2025-11-17.

1. **[^](#cite_ref-42)** ["perlpod – the Plain Old Documentation format"](http://perldoc.perl.org/perlpod.html). Retrieved 2011-09-12.

1. **[^](#cite_ref-43)** ["Pod::ParseUtils – helpers for POD parsing and conversion"](https://search.cpan.org/~bradapp/PodParser-1.20/lib/Pod/ParseUtils.pm). Retrieved 2011-09-12.

1. ^ [***a***](#cite_ref-perl6_44-0) [***b***](#cite_ref-perl6_44-1) ["Perl 6 Documentation – Syntax (Comments)"](https://docs.perl6.org/language/syntax#Comments). Retrieved 2017-04-06.

1. ^ [***a***](#cite_ref-triple_45-0) [***b***](#cite_ref-triple_45-1) ["Python 3 Basic Syntax"](https://web.archive.org/web/20210819164828/https://www.tutorialdocs.com/tutorial/python3/python3-basic-syntax.html). Archived from [the original](https://www.tutorialdocs.com/tutorial/python3/python3-basic-syntax.html) on 19 August 2021. Retrieved 25 February 2019. Triple quotes are treated as regular strings with the exception that they can span multiple lines. By regular strings I mean that if they are not assigned to a variable they will be immediately garbage collected as soon as that code executes. hence are not ignored by the interpreter in the same way that #a comment is.

1. **[^](#cite_ref-46)** ["Python tip: You can use multi-line strings as multi-line comments"](https://twitter.com/gvanrossum/status/112670605505077248), 11 September 2011, Guido van Rossum

1. **[^](#cite_ref-47)** ["Literate programming"](http://www.haskell.org/haskellwiki/Literate_programming#Bird_Style). *haskell.org*.

1. **[^](#cite_ref-48)** ["Programming in Lua 1.3"](http://www.lua.org/pil/1.3.html). *www.Lua.org*. Retrieved 2017-11-08.

1. **[^](#cite_ref-MSSQL_49-0)** Talmage, Ronald R. (1999). [*Microsoft SQL Server 7*](https://archive.org/details/microsoftsqlserv00talm). Prima Publishing. [ISBN](/source/ISBN_(identifier)) [978-0-7615-1389-6](https://en.wikipedia.org/wiki/Special:BookSources/978-0-7615-1389-6).

1. **[^](#cite_ref-MySQL_50-0)** ["MySQL 8.0 Reference Manual"](https://dev.mysql.com/doc/refman/8.0/en/comments.html). Oracle Corporation. Retrieved January 2, 2020.

1. **[^](#cite_ref-SQLite_51-0)** ["SQL As Understood By SQLite"](https://www.sqlite.org/lang_comment.html). SQLite Consortium. Retrieved January 2, 2020.

1. **[^](#cite_ref-PostgreSQL_52-0)** ["PostgreSQL 10.11 Documentation"](https://www.postgresql.org/docs/10/sql-syntax-lexical.html#SQL-SYNTAX-COMMENTS). The PostgreSQL Global Development Group. Retrieved January 2, 2020.

1. **[^](#cite_ref-Oracle_53-0)** ["Oracle® Database SQL Reference"](https://docs.oracle.com/cd/B13789_01/server.101/b10759/sql_elements006.htm). Oracle Corporation. Retrieved January 2, 2020.

1. **[^](#cite_ref-54)** ["Leave a comment in running-config"](https://learningnetwork.cisco.com/thread/71302). *Cisco Learning Network (discussion forum)*.

1. **[^](#cite_ref-55)** ["Managing Configuration Files Configuration Guide, Cisco IOS XE Release 3S (ASR 900 Series)"](http://www.cisco.com/c/en/us/td/docs/ios-xml/ios/config-mgmt/configuration/xe-3s/asr903/config-mgmt-xe-3s-asr903-book/cm-config-files.html).

1. **[^](#cite_ref-56)** [macros.extractDocCommentsAndRunnables](https://nim-lang.github.io/Nim/macros.html#extractDocCommentsAndRunnables%2CNimNode)

1. **[^](#cite_ref-57)** Kathleen Jensen, Niklaus Wirth (1985). *Pascal User Manual and Report*. Springer-Verlag. [ISBN](/source/ISBN_(identifier)) [0-387-96048-1](https://en.wikipedia.org/wiki/Special:BookSources/0-387-96048-1).

1. **[^](#cite_ref-58)** Niklaus Wirth (1983). *Programming in Modula-2*. Springer-Verlag. [ISBN](/source/ISBN_(identifier)) [0-387-15078-1](https://en.wikipedia.org/wiki/Special:BookSources/0-387-15078-1).

1. **[^](#cite_ref-59)** *Martin Reiser, Niklaus Wirth (1992). *Programming in Oberon*. Addison-Wesley. [ISBN](/source/ISBN_(identifier)) [0-201-56543-9](https://en.wikipedia.org/wiki/Special:BookSources/0-201-56543-9).

1. **[^](#cite_ref-InsecureComments_60-0)** Andress, Mandy (2003). *Surviving Security: How to Integrate People, Process, and Technology*. CRC Press. [ISBN](/source/ISBN_(identifier)) [978-0-8493-2042-2](https://en.wikipedia.org/wiki/Special:BookSources/978-0-8493-2042-2).

## Further reading

- Movshovitz-Attias, Dana and Cohen, William W. (2013) [Natural Language Models for Predicting Programming Comments](https://www.cs.cmu.edu/~dmovshov/papers/dma_acl2013.pdf). In Association for Computational Linguistics (ACL), 2013.

## External links

- [How to Write Comments](https://web.archive.org/web/20110708033309/http://dkrukovsky.blogspot.com/2005/07/how-to-write-comments.html) by Denis Krukovsky

- [Source Code Documentation as a Live User Manual](https://web.archive.org/web/20070722211609/http://www.ptlogica.com/TwinText/resource/liveuser.pdf) by PTLogica

- [How to Write Comments for the Javadoc Tool](https://www.oracle.com/technetwork/java/javase/tech/index-137868.html)

---
Adapted from the Wikipedia article [Comment (computer programming)](https://en.wikipedia.org/wiki/Comment_(computer_programming)) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Comment_(computer_programming)?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
