A function (or method) that uses a high number of parameters makes maintenance more difficult:

Restrict the number of parameters for a function, according to the reason for the high number:

When a function is part of a published interface, one possible solution is to add a new, wrapper function to the interface that has a tidier signature. Alternatively, you can publish a new version of the interface that has a better design. Clearly, however, neither of these solutions is ideal, so you should take care to design interfaces the right way from the start.

The practice of adding parameters for future extensibility is especially bad. It is confusing to other programmers, who are uncertain what values they should pass in for these unnecessary parameters, and it adds unused code that is potentially difficult to remove later.

In the following example, although the parameters are logically related, they are passed into the print_annotation function separately.

In the following modified example, the print_annotation function is simplified by logically grouping the related parameters into a single class. An instance of the class can then be passed into the function instead, as shown below.

In the following example, the print_membership function has too many responsibilities, and so needs to be passed four arguments.

In the following modified example, print_membership has been broken into four functions. (For brevity, only one function is shown.) As a result, each new function needs to be passed only one of the original four arguments.

  • M. Fowler, Refactoring. Addison-Wesley, 1999.