FANDOM


A comment contains text intended to describe the source which is not executable. The text may be in any language (or none at all). Comments are typically used to either explain obscure code or temporarily remove some code from the program. Comments can be classified by:

Inline comments Edit

Inline comments are generally those that use a newline character to indicate the end of a comment, and an arbitrary delimiter or sequence of tokens to indicate the beginning of a comment.

Examples:

Symbol Languages
C Fortran; the 'C' must be in column 1 of a line to indicate a comment.
REM Basic, COMMAND.COM, cmd.exe
# Perl, Python, Ruby, Windows PowerShell, PHP, Maple
% TeX, Prolog, MATLAB, Erlang, S-Lang
// C, C++, C#, Object Pascal (Delphi), Java, JavaScript, PHP
' Visual Basic, VBScript
! Fortran, Basic Plus
; AutoHotkey, Autoit, Lisp, Scheme, many assemblers
-- Euphoria, Haskell, SQL, ADA, AppleScript, Eiffel, Lua
* Cobol, many assemblers
|| Curl

Block comments Edit

Block comments are generally those that use a delimiter to indicate the beginning of a comment, and another delimiter to indicate the end of a comment. In this context, whitespace and newline characters are not counted as delimiters.

Examples:

Symbol Languages
/* */ AutoHotkey, C, C++, C#, Java, JavaScript, PHP, SQL, Visual Prolog, CSS
""" """ Python, Ruby[1]
''' ''' Python[1]
=begin =cut Perl, Ruby
{- -} Haskell
(* *) Object Pascal (Delphi), ML, Mathematica, Pascal, Applescript, OCaml
{ } Object Pascal (Delphi), Pascal
<!-- --> HTML
|# #| Curl

Unique variants Edit

Fortran Edit

  • The indentation of lines in FORTRAN 66/77 is significant. The actual statement is in columns 7 through 72 of a line. Any non-space character in column 6 indicates that this line is a continuation of the previous line. A 'C' in column 1 indicates that this entire line is a comment. Columns 1 though 5 may contain a number which serves as a label. Columns 73 though 80 are ignored and may be used for comments; in the days of punched cards these columns contained a sequence number so that the deck of cards could be sorted into the correct order if someone accidentally dropped the cards. Fortran 90 removed the need for the indentation rule and added traditional inline comments, using the ! character as the comment delimiter.

Perl Edit

  • Block comments in Perl are considered part of the documentation, and are given the name Plain Old Documentation (POD). Technically, Perl does not have a convention for including block comments in source code, but POD is routinely used as a workaround.

PHP Edit

  • PHP supports standard C/C++ style comments, but also supports Perl style as well.

Python Edit

  • The use of the triple-(double)quotes although sometimes used to comment-out lines of source, does not actually form a comment. The enclosed text becomes a string, usually a string statement. Python usually ignores a lone string as a statement (except when a string is the first statement in the body of a module, class or function; see docstring).

Ruby Edit

  • As with Python and Perl, Ruby has no specific block-comment syntax. However, like Perl, documentation blocks can be used as block comments as they are ignored by the interpreter.

Curl Edit

  • Curl supports block comments with user-defined tags as in |foo# ... #foo|

Esoteric languages Edit

Comment comparison Edit

There is a wide variety of syntax styles for declaring comments in source code. BlockComment in italics is used here to indicate block comment style. InlineComment in italics is used here to indicate inline comment style.

  • Ada, Eiffel, Euphoria, Lua, Occam, SPARK, ANSI SQL, ToolBook OpenScript, and VHDL:
    • -- InlineComment
  • ALGOL 60:
    • comment BlockComment;
  • ALGOL 68:
    • ¢ BlockComment ¢
    • comment BlockComment comment
    • co BlockComment co
    • # BlockComment #
    • £ BlockComment £
  • AppleScript:
    • (* BlockComment *)
    • -- InlineComment
  • Assembly language: (varies)
    • ; InlineComment   one example (most assembly languages use line comments only)
  • AutoHotkey:
    • ; InlineComment
    • /* BlockComment */
  • AWK, Bash, Bourne shell, C shell, Maple, Python, R, Tcl, and Windows PowerShell:
    • # InlineComment
  • BASIC (various dialects):
    • 'InlineComment (not all dialects)
    • REM InlineComment (REM is short for "Remark")
  • C (K&R, ANSI/C89/C90), CHILL, CSS, PL/I, and REXX:
    • /* BlockComment */
  • C (C99), C++, and JavaScript:
    • /* BlockComment */
    • // InlineComment
  • C#
    • /* BlockComment */
    • /** BlockComment */ (XML documentation comment)
    • // InlineComment
    • /// InlineComment (XML documentation comment)
  • Cobol:
    • * InlineComment when * is in column 7
  • Curl:
    • || InlineComment</code?
    • <code>|# BlockComment #|
    • |foo# BlockComment #foo|
  • D:
    • /* BlockComment */
    • // InlineComment
    • /+ BlockComment +/ (nestable)
  • DCL:
    • $! InlineComment
  • ECMAScript (JavaScript, ActionScript, etc):
    • /* BlockComment */
    • // InlineComment
  • Forth:
    • ( BlockComment )
    • \ InlineComment
  • FORTRAN 66/77:
    • C InlineComment (the letter 'C' in the first column makes the entire line a comment).
  • Fortran 90:
    • ! InlineComment (all characters on the line, from the exclamation mark onwards, are comments)
  • HTML (see SGML below)
  • Java:
    • // InlineComment
    • /* BlockComment */
    • /** BlockComment */ (Javadoc documentation comment)
  • Lisp and Scheme
    • #| BlockComment |#
    • ; InlineComment
  • Maple:
    • # InlineComment
  • Mathematica:
    • % (* BlockComment *)
  • Matlab:
    • % BlockComment;
    • %{
      Use this to comment out multiple lines without placing a "%" in front of every single one.
      Nothing besides %{ must appear on that line

      %}
  • Object Pascal (Delphi):
    • (* BlockComment *)
    • { BlockComment }
    • // InlineComment
  • Pascal, Modula-2, Modula-3, Oberon, and ML:
    • (* BlockComment *) (OCaml comments are nestable)
  • Perl and Ruby:
    • # InlineComment
    • =begin
      BlockComment
      =cut
      (POD documentation comment)
    • __END__
      Comments after end of code
  • PHP:
    • # InlineComment
    • // InlineComment
    • /* BlockComment */
  • PILOT:
    • R:InlineComment
  • PL/SQL and TSQL:
    • /* BlockComment */
    • -- InlineComment
  • REALbasic:
    • ' InlineComment
    • // InlineComment
    • rem InlineComment
  • SAS:
    • * BlockComment;
    • /* BlockComment */
  • Seed7:
    • (* BlockComment *)
    • # InlineComment
  • SGML, including HTML:
    A comment declaration starts with <!, followed by zero or more comments, followed by >. A comment starts and ends with --, and does not contain any occurrence of --. Valid examples are:
    • <!-- BlockComment -- -- BlockComment -->,
    • <!------ BlockComment -->, or
    • <!>.
  • Smalltalk:
    • "BlockComment"
  • Smarty:
    • {* BlockComment *}
  • Standard ML:
    • (* BlockComment *)
  • TeX, LaTeX, PostScript, Erlang, and S-Lang:
    • % InlineComment
  • Texinfo:
    • @c InlineComment
    • @comment InlineComment
  • TUTOR:
    • * InlineComment
    • command $$ InlineComment
  • Visual Basic:
    • ' InlineComment
    • Rem InlineComment
  • Visual Basic .NET
    • ' InlineComment
    • ''' InlineComment (XML documentation comment)
    • Rem InlineComment
  • Visual Prolog:
    • /* BlockComment */
    • % InlineComment
  • XML, including XHTML:
    • <!--BlockComment--> (comment must not contain -- and must not start or end with single -)
Smallwikipedialogo.png This page uses content from Wikipedia. The original article was at Comparison of programming languages (syntax)#Comments. The list of authors can be seen in the page history. As with the Programmer's Wiki, the text of Wikipedia is available under the GNU Free Documentation License.

Cite error: <ref> tags exist, but no <references/> tag was found

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.