mirror of
https://github.com/github/codeql.git
synced 2025-12-24 20:56:33 +01:00
46 lines
1.2 KiB
XML
46 lines
1.2 KiB
XML
<!DOCTYPE qhelp PUBLIC
|
|
"-//Semmle//qhelp//EN"
|
|
"qhelp.dtd">
|
|
<qhelp>
|
|
<overview>
|
|
<p>
|
|
Functions with many parameters are hard to understand and to use, and should be avoided.
|
|
</p>
|
|
|
|
</overview>
|
|
<recommendation>
|
|
|
|
<p>
|
|
In some cases it may be possible to split the function into multiple smaller functions, each of which only
|
|
requires a subset of parameters. Where this is not possible, consider passing the parameters as an object
|
|
literal and accessing them as properties of that literal.
|
|
</p>
|
|
|
|
</recommendation>
|
|
<example>
|
|
|
|
<p>
|
|
In the following example, function <code>sendRecord</code> has nine parameters. Such a function is hard
|
|
to use, since the user has to remember in which order to pass the arguments.
|
|
</p>
|
|
|
|
<sample src="examples/TooManyParameters.js" />
|
|
|
|
<p>
|
|
The function should be refactored to use a parameter object instead, with each parameter of the old
|
|
function corresponding to a property of the object as in the following code. Of course, any calls to the
|
|
function have to be updated accordingly.
|
|
</p>
|
|
|
|
<sample src="examples/TooManyParametersGood.js" />
|
|
|
|
</example>
|
|
<references>
|
|
|
|
|
|
<li>Cunningham & Cunningham, Inc: <a href="http://c2.com/cgi/wiki?TooManyParameters">Code Smell: Too Many Parameters</a>.</li>
|
|
|
|
|
|
</references>
|
|
</qhelp>
|