Comment density falls below threshold
Description
Polyspace® calculates the comment density percentage of a file by taking the ratio of
comments to number of executable lines in the file and then multiplying the ratio by 100. For
instance, a comment density 20
indicates that the file contains 20%
comments and 80% code statements. This defect is raised when the comment density falls below
the specified threshold. For details about how Polyspace calculates comment density, see Comment Density
Polyspace uses the default threshold 80 unless you specify a threshold. To specify a
selection file where you can set the threshold, use the option Set checkers by file (-checkers-selection-file)
or Checkers activation file
(-checkers-activation-file)
.
When you import comments from previous analyses by using polyspace-comments-import
, Polyspace copies any review information on the code metric Comment Density
in the previous result to this
checker in the current result. If the current result contains the same code metric, the review
information is copied to the code metric as well.
Risk
Violation of this checker might indicate that:
The module is not properly documented.
The module is overly long and dense.
The module might contain unexpected or unplanned development.
These factors make the module difficult to maintain and debug.
Fix
To fix this defect:
Put more comments between your statements that conveys the developer intent.
Alternatively, reduce the number of statements in the module. If the module contains multiple functions, consider splitting the module and documenting them separately.
To fix this check, either refactor your code or change the checker threshold. A best practice is to check the complexity of a module early in development to avoid costly post-development refactoring.
Examples
Check Information
Group: Software Complexity |
Language: C | C++ |
Acronym:
SC02
|
Default Threshold: 20 |
Version History
Introduced in R2021a