Number of lines in function body exceeds threshold
The number of lines in the body of a function is greater than the defined threshold
Since R2021a
Description
This defect is raised on a function when the number of lines within the body of the
function is greater than the defined checker threshold. For details about how Polyspace
calculates the number of lines in the body of a function, see Number of Lines Within Body
Polyspace® uses the default threshold 1200 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 Number of Lines Within Body
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 function is too long. Lengthy function are difficult to read and understand. Maintaining, testing and debugging lengthy functions might be costly in terms of resource and time.
Fix
To fix this check, either refactor your code or change the checker threshold. When refactoring the code, make the functions modular. That is, design your code so that each function performs one specific task with as little side effect as possible. Modular design of function make them easy to test, debug, and maintain. Modular functions also enables efficient code reuse and might reduce code duplication.
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:
SC10
|
Default Threshold: 1200 |
Version History
Introduced in R2021a