Language scope exceeds threshold
The language scope of a function is greater than the defined threshold
Since R2021a
Description
Language scope represents the cost of maintaining or updating a function. For instance, if
an operand occurs many times in a function, then changing the operand name is costly. The
language scope of such a function would be high. This defect is raised when the language scope
of a function exceeds the defined threshold. For details about how Polyspace calculates
language scope, see Language Scope
.
Note
The language scope calculated by Polyspace® is a floating point number. In this checker, the floating point language scope is converted to an integer by rounding it to the second decimal place and then multiplying it by 100.
Polyspace uses the default threshold 400 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 Language Scope
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:
Change to an operand might require many change in the function.
The function might be performing multiple tasks at once.
The function might have high degree of interdependency with other functions.
These factors make the module difficult to maintain and debug.
Fix
To fix this check, either refactor your code or change the checker threshold. When refactoring the code, design the functions in your code so that:
Each function performs one specific task.
The functions have minimal side effects on other functions.
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:
SC18
|
Default Threshold: 400 |
Version History
Introduced in R2021a