Home
Functions Or Events should not have too many parameters
Description
This rule states that functions or events should not have too many parameters. Having too many parameters can make the code difficult to read and understand, and can lead to errors. It is best practice to limit the number of parameters to a manageable number, usually no more than 5-10. Any more than that should be split into multiple functions or events. This will help make the code more readable and easier to maintain.
Key Benefits
- Reduced Complexity: Functions or events should not have too many parameters, as this reduces complexity and makes them easier to read and debug.
- Improved Performance: Fewer parameters also mean fewer calculations, leading to improved performance.
- Increased Readability: Fewer parameters also make the code more readable, making it easier to understand and maintain.
Non-compliant Code Example
private function string TestFunctionCall (string p1,string p2,string p3,string p4,string p5,string p6,string p7,string p8,string p9,string p10,int cnt)//Non compliant code (Allowed less than 10 number of parameters in the function or events)
return cnt
end function
Compliant Code Example
type s_parameters from structure
string p1
string p2
string p3
string p4
string p5
string p6
string p7
string p8
string p9
string p10
int cnt
end type
private function string TestFunctionCall (s_parameters p)//Compliant code
return cnt
end function