You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Limit number of method/closure parameters rule #415
Time to time I raise this issue with colleagues: there is no proven number to stick, but IMHO anything with 5 or more parameters should be considered as suspicious (might be a good place to use "Introduce Parameter object" refactoring).
I see it as an AST rule that raises warning for methods/functions/closures with 5 or more arguments (configurable).
Edit: probably it should ignore init methods though (value objects usually have tons of parameters)
@scottrhoyt that's a good question indeed 👍
Just thinking out loud: declaration of method with 4+ parameters is not often a problem, developer has hard times when he reads place where such method is called or invokes such method. Assuming that I would say that we can:
make requirement less strict for method containing optional arguments (math to be discussed)
completely ignore parameters with default values because they can be totally ignored when calling method
Without thinking about it too much, I think I would vote for option number 2 since it is simpler and clearer. Ultimately I think it is more important for this rule to protect potential callers as opposed to the function writer.
Activity
scottrhoyt commentedon Jan 25, 2016
Interesting idea. Do you think this should or shouldn't count parameters with default values?
delebedev commentedon Jan 25, 2016
@scottrhoyt that's a good question indeed 👍
Just thinking out loud: declaration of method with 4+ parameters is not often a problem, developer has hard times when he reads place where such method is called or invokes such method. Assuming that I would say that we can:
scottrhoyt commentedon Jan 26, 2016
Without thinking about it too much, I think I would vote for option number 2 since it is simpler and clearer. Ultimately I think it is more important for this rule to protect potential callers as opposed to the function writer.
reference #415 in changelog