Java Reference
In-Depth Information
a = b //*divisor:*/c
+ d;
/* Equivalent to a = b + d; */
Compliant Solution
Use a consistent style of commenting.
// Nice simple comment
int i; // Counter
Noncompliant Code Example
There are other misuses of comments that should be avoided. This noncompliant code ex-
ample uses the character sequence /* to begin a comment, but neglects to use the delim-
iter */ to end the comment. Consequently, the call to the security-critical method is not
executed. A reviewer examining this page could incorrectly assume that the code is ex-
ecuted.
Click here to view code image
/* Comment with end comment marker unintentionally omitted
security_critical_method();
/* Some other comment */
Using an editor that provides syntax highlighting or that formats the code to identify
issues such as missing end comment delimiters can help detect accidental omissions.
Because missing end delimiters are error prone and often viewed as a mistake, this ap-
proach is not recommended for commenting out code.
Compliant Solution
This compliant solution demonstrates the recommended way to mark code as “dead.” It
also takes advantage of the compiler's ability to remove unreachable (dead) code. The
code inside the if block must be syntactically correct. If other parts of the program later
change in a way that would cause syntax errors, the unexecuted code must be brought up
to date to correct the problem. Then, if it is needed again in the future, the programmer
need only remove the surrounding if statement and the NOTREACHED comment.
Search WWH ::




Custom Search