Comment (computer programming): Difference between revisions

Content deleted Content added
Clarify how comments are ignored by a translator yet are parsed by other tools
Common attributes: Organize info better
Line 26:
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''' blockis or[[delimiter#Bracket sequencedelimiters|delimited]] ofwith linetext commentsthat located nearmarks the topstart ofand anend associatedof programmingcomment topic,text. suchIt ascan beforespan amultiple symbol declarationlines or atoccupy theany toppart of a file,line. isSome calledlanguages aallow ''prologueblock comment''.comments Ato commentbe thatrecursively isnested on onlyinside one lineanother, usuallybut afterothers programdo code, is called an ''inline comment''not.<ref name="JBDixit000Higham000">{{cite book | last = Dixit | first = J.B. | title = Computer Fundamentals and Programming in C | publisher = Laxmi Publications | year = 2003 | isbn = 978-81-7008-882-0 }}</ref>
 
A '''block comment''' is [[delimiter#Bracket delimiters|delimited]] with text that marks the start and end of the block. It can span multiple lines or occupy any part of a line. Some languages (such as [[MATLAB]]) allow block comments to be recursively nested inside one another, but others (such as [[Java (programming language)|Java]]) do not.<ref name="Higham000">{{cite book
| title = MATLAB Guide
| first = Desmond
Line 48 ⟶ 46:
| access-date = 2007-07-24
| date = 2000-03-04
Most}}</ref> 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.<ref name="javadude000" /> Many languages support both block and line comments {{endash}} using different delimiters for each. For example, [[C (programming language)|C]], [[C++]] and their many derivatives support block comments delimited by <code>/*</code> and <code>*/</code> and line comments delimited by <code>//</code>. Other languages support only one type of comment.<ref name="javadude000" />
}}</ref>
 
In modern languages, a '''line comment''' starts with a delimiter and continues until the end of the line. Some older languages designated a column at which subsequent text is considered comment text.<ref name="javadude000" />
 
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, is called a '''prologue comment'''. A comment that is located on the same line as and to the right of program code is called an '''inline comment'''.<ref name="JBDixit000">{{cite book | last = Dixit | first = J.B. | title = Computer Fundamentals and Programming in C | publisher = Laxmi Publications | year = 2003 | isbn = 978-81-7008-882-0 }}</ref> Both prologue and inline comments can be represented as either line or block comments.
Most modern languages support both block and line comments {{endash}} using different delimiters for each. For example, [[C (programming language)|C]], [[C++]] and their many derivatives support block comments delimited by <code>/*</code> and <code>*/</code> and line comments delimited by <code>//</code>. Other languages support only one type of comment.<ref name="javadude000" />
 
==Examples of use==