A typical code smell known as unused function parameters refers to parameters declared in a function but not used anywhere within the function’s body. While this might seem harmless at first glance, it can lead to confusion and potential errors in your code. Disregarding the values passed to such parameters, the function’s behavior will be the same, but the programmer’s intention won’t be clearly expressed anymore. Therefore, removing function parameters that are not being utilized is considered best practice.
The rule ignores the following cases:
throw statement (i.e. where the intention is to
simulate an abstract class).
override function doSomething(a:int):void { // ignored
compute(a);
}
...
class AbstractSomething {
public function doSomething(a:int) { // ignored
throw new IllegalOperationError("doSomething() is abstract");
}
...
interface I {
function action(a:int, b:int);
}
class C extends I {
function action(a:int, b:int) { // ignored
return doSomethignWith(a);
}
}
function clickHandler(event:MouseEvent):void { // ignored
trace("click");
}
Having unused function parameters in your code can lead to confusion and misunderstanding of a developer’s intention. They reduce code readability and introduce the potential for errors. To avoid these problems, developers should remove unused parameters from function declarations.
function doSomething(a:int, b:int):void // "b" is unused
{
compute(a);
}
function doSomething(a:int):void
{
compute(a);
}