Method design

There are several method design conventions I adhere to in order to make the code more readable, comprehensible and easily maintainable.

Parameter order
Method parameters ordered in a certain standard order make the code more readable. I prefer to list input parameter first, input-output parameters second, output parameters third, and status parameters last.

Maximum number of parameters
It is tough for a developer to keep track of more than 7 items at a time. Keeping the maximum number of parameter up to 7 reduces complexity and increases readability. If a method needs to have more than 7 parameters, then it may be necessary to combine the parameters in an object and use it as a single parameter.

Method length
The length of a method influences its maintainability. Long methods tend to be complex. In my experience, methods longer than 2 pages are less comprehensible. Therefore, they should not exceed 2 pages.

These are my method design guidelines. Do you have any? What are they? Feel free to start discussion in the comments.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.