If a class has a number of methods that require common parameters to be passed in, be consistent when ordering the parameters.

For example, take a look at these method signatures from an interface where the Request parameter is in a different place every time:

:
void validate(Request request, ValidationResult result, int maxPages);
:
ReportResult execute(String title, Request request);
:
ReportParameter[] getParameters(int accessLevel, History history, Request request);
:

It would be much neater if all the Request parameters came first:

:
void validate(Request request, ValidationResult result, int maxPages);
:
ReportResult execute(Request request, String title);
:
ReportParameter[] getParameters(Request request, int accessLevel, History history);
:

In another example, the pageCount and pageSize are switched in two similar method names, which adds confusion since both parameters are integers.

:
int getLastPage(int pageCount, int pageSize);
:
int getTotalSize(int pageSize, int pageCount);
:

It would be much better to write parameters in the same order each time.

:
int getLastPage(int pageCount, int pageSize);
:
int getTotalSize(int pageCount, int pageSize);
:
blog comments powered by Disqus