Number of parameters in method (NumberOfParams)¶
Type | Scope | Severity | Activated by default |
Minutes to fix |
Tags |
---|---|---|---|---|---|
Code smell |
BSL OS |
Minor |
Yes |
30 |
standard brainoverload |
Parameters¶
Name | Type | Description | Default value |
---|---|---|---|
maxParamsCount |
Integer |
Max number of params count |
7 |
Description¶
It is not recommended to declare many parameters in functions (best practice to use not more than seven parameters). In So doing there should not be many parameters with default values set (best practice to have not more than three such parameters). Otherwise code readability decreases. For example it is easy to make a mistake in number of commas passing optional parameters.
If need to pass many parameters to a function, it is recommended to group same-type parameters into one or more composite parameters of type Structure.
Examples¶
Incorrect:
// Create an item in catalog "Goods"
Procedure CreateSKU(Name, Goods, Units, Weight, Check = True)
// ...
EndProcedure
Correct:
Group parameters, having goods item properties into Structure Values.
// Create item in catalog "Goods"
Procedure CreateNewGoods(Values, Check = True)
EndProcedure
Sources¶
Snippets¶
Diagnostic ignorance in code¶
// BSLLS:NumberOfParams-off
// BSLLS:NumberOfParams-on
Parameter for config¶
"NumberOfParams": {
"maxParamsCount": 7
}