Comment

From CodeCodex

Comments are a programming language construct that provides a mechanism for embedding information in the source code that is (generally) ignored by compilers but may be of use to software developers or other programming tools that process the source.

Implementations[edit]

Ada[edit]

-- Ada comments start with a pair of hyphens and continue to the end of the line.

C[edit]

/*
 * Check if we are over our maximum process limit, but be sure to
 * exclude root. This is needed to make it possible for login and
 * friends to set the per-user process limit to something lower
 * than the amount of processes root is running. -- Rik
 */
if (atomic_read(&p->user->processes) >= p->rlim[RLIMIT_NPROC].rlim_cur
    && !capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE))
    goto bad_fork_free;

Source: fork.c from the Linux kernel source

// C99 also supports C++-style line comments

C++[edit]

/*
    C++ supports C-style block comments
    which can extend across multiple lines
    or occupy just part of a line
*/

// C++ also allows comments which begin with "//" and extend to the end of the line.

Erlang[edit]

% A single-line comment begins with a % and continues
% until the end of the line.

Go[edit]

/*
    Go supports C-style block comments
    which can extend across multiple lines
    or occupy just part of a line
*/

// Go also supports C++-style line comments

Haskell[edit]

-- this is a line-style comment

{- this is a block-style comment
   {- it nests properly -} -}

Java[edit]

/* Java supports C-style block comments */

/**
 * Registers the text to display in a tool tip.   The text 
 * displays when the cursor lingers over the component.
 *
 * @param text  the string to display.  If the text is null, 
 *              the tool tip is turned off for this component.
 */
public void setToolTipText(String text) {

Source: Sun Microsystems javadoc documentation; the comment is designed to be read by the javadoc processor

// Java also allows comments which begin with "//" and extend to the end of the line.

OCaml[edit]

(* this is a block-style comment
   (* it nests properly *) *)

Perl[edit]

# single line comment

=pod
Multi
line
documentation
=cut

PHP[edit]

C-style block comment:

/*
 * Scan forwards to find beginning of another run of changes.
 * Also keep track of the corresponding point in the other file.
 *
 * Throughout this code, $i and $j are adjusted together so that
 * the first $i elements of $changed and the first $j elements
 * of $other_changed both contain the same number of zeros
 * (unchanged lines).
 * Furthermore, $j is always kept so that $j == $other_len or
 * $other_changed[$j] == false.
 */
    while ($j < $other_len && $other_changed[$j])
        $j++;

Source: from MediaWiki, the software which powers Wikipedia, an on-line collaborative encyclopedia

// C++-style line comment

# Shell-style line comment

Python[edit]

# single line comment

'''Multi-line string. Not a comment in itself. But it is usually used as the first line of a function or class body,
in what is known as a "documentation string".'''

Ruby[edit]

Ruby has two different comment styles, single line and block comments.

# A single-line comment begins with a # and continues
# until the end of the line.

=begin
A block comment begins with =begin and continues until =end.
Both parts must be at the beginning of the line without any
other text or whitespace.
=end

Scheme[edit]

; this is a comment
(+ 1 1) ;we are calculating 1 + 1

Seed7[edit]

(*
    Seed7 supports block comments
    which can extend across multiple lines
    or occupy just part of a line. (* By the way: Seed7 comments can nest *)
*)

# Seed7 also allows comments which begin with "#" and extend to the end of the line.

MS-SQL[edit]

/*MS SQL supports
large code blocks
using slash-asterisk
and asterisk-slash */
-- as well as inline comments (which are terminated by End-Of-Line (EOL))

Visual Basic[edit]

 '
 ' Cut off HKEY_USERS\ if present.
 ' This makes interoperating with regedit easier.
 '
 If Len(SIDstring) > 11 Then
     If Left(SIDstring, 11) = "HKEY_USERS\" Then
         SIDstring = Mid(SIDstring, 12)
     End If
 End If
 
 '
 ' Open the WMI Service and retrieve the SID
 '
 On Error Resume Next
 Set SIDobject = GetObject( _
     "winmgmts:{impersonationLevel=Impersonate}" _
     ).Get("Win32_SID.SID='" & SIDstring & "'")
 If Err Then
     MsgBox "Could not retrieve the SID.", vbOkOnly, "Sorry"
     Exit Do
 End If

Source: Adapted from an example illustrating ways to create system administration tools.