Single-line Comments

Single-line Comments

A single-line comment consists of the characters // followed by comment text. There is always a single space between the // and the comment text. A single line comment must be at the same indentation level as the code that follows it. More than one single-line comment can be grouped together to make a larger comment; however, if the number of lines is very large, consider using a block comment instead. A single-line comment or comment group should always be preceded by a blank line, unless it is the first line in a block. If the comment applies to a group of several following statements, then the comment or comment group should also be followed by a blank line. If it applies only to the next statement (which may be a compound statement), then do not follow it with a blank line. Example:

 // Traverse the linked list, searching for a match for (Node node = head; node.next != null; node = node.next) { 

Single-line comments can also be used as trailing comments. Trailing comments are similar to single-line comments except they appear on the same line as the code they describe. At least one space should separate that last non-white space character in the statement and the trailing comment. If more than one trailing comment appears in a block of code, they should all be aligned to the same column. Example:

 if (!isVisible())             return;             // nothing to do        length++;               // reserve space for null term. 

Avoid the assembly language style of commenting every line of executable code with a trailing comment.



Software Development. Building Reliable Systems
Software Development: Building Reliable Systems
ISBN: 0130812463
EAN: 2147483647
Year: 1998
Pages: 193
Authors: Marc Hamilton

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net