Comment (computer programming): Difference between revisions

Content deleted Content added
Examples: It's syntax; not typography
Examples: Limit examples by grouping by similar syntax
Line 341:
==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.
===Comparison===
{{main|Comparison of programming languages (syntax)#Comments}}
 
====C=By group===
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.
 
====Curly brace languages====
Many of the [[curly brace language]]s such as C, C++ and their many derivatives delimit a line comment with {{code|//}} and a block comment with {{code|/*}} and {{code|*/}}. Originally, C lacked the line comment, but it was added in [[C99]]. The list of languages that use this syntax is long but a few of the more notable include: C, C++, [[C# (programming language)|C#]], [[Java (programming language)|Java]], [[Javascript]]. For example:
 
<syntaxhighlight lang="c">
/*
* Check if we are over our maximum process limit, but be sure to exclude root.
* exclude root. This is needed to make it possible for login andto set per-user
* process *limit thanto thesomething amountlower ofthan processes root is running. -- Rik
*/
bool isOverMaximumProcessLimit() {
// TODO implement
</syntaxhighlight>
 
===By language===
 
====Ada====
Line 410 ⟶ 425:
End Sub
End Class
</syntaxhighlight>
 
====C====
In [[C (programming language)|C]], [[C++]] and many related languages, the line comment delimiter is {{code|//}} and a block is delimited by {{code|/*}} and {{code|*/}}. Originally, C lacked the line comment, but it was added in [[C99]]. For example:
 
<syntaxhighlight lang="c">
/*
* 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;
</syntaxhighlight>
 
Line 536:
\end{code}
Here more explanation using \LaTeX{} markup
</syntaxhighlight>
 
====Java====
This [[Java (programming language)|Java]] code fragment shows both block and line comments. The block comment is designed to be processed by [[Javadoc]].
<syntaxhighlight lang="java">
/**
* This is a block comment in Java.
* The setToolTipText method registers the text to display in a tool tip.
* The text is displayed when the cursor lingers over the component.
*
* @param text The string to be displayed. If 'text' is null,
* the tool tip is turned off for this component.
*/
public void setToolTipText(String text) {
// This is an inline comment in Java. TODO: Write code for this method.
</syntaxhighlight>
 
====JavaScript====
[[JavaScript (programming language)|JavaScript]] uses // to precede comments and /* */ for multi-line comments.
 
<syntaxhighlight lang="javascript">
// A single line JavaScript comment
var iNum = 100;
var iTwo = 2; // A comment at the end of line
/*
multi-line
JavaScript comment
*/
</syntaxhighlight>