Number of function parameters exceeds threshold
The number of arguments of a function is greater than the defined threshold
Since R2021a
Description
This defect is raised on a function when the number of its arguments is greater than the
defined checker threshold. For details about how Polyspace calculates the number of
parameters, see Number of Function
Parameters
Polyspace® uses the default threshold 5 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 Function Parameters
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 indicates that:
The function might have unacceptably high degree of dependence on other functions.
The function might be performing more than one specific task. A best practice is to delegate one specific task to one function.
The function might contain unexpected or unplanned development.
The function might hinder performance because registers cannot hold all parameters.
These factors make the function difficult to maintain and debug.
Fix
To fix this check, either refactor your code or change the threshold in the checker selection XML. You might want to split the function into smaller chunks that performs a specific task and does not take more than the number of parameters specified as threshold. If the parameters of a functions are related, you might consider bundling them into structures.
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:
SC07
|
Default Threshold: 5 |
Version History
Introduced in R2021a