Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit number of method/closure parameters rule #415

Closed
delebedev opened this issue Jan 25, 2016 · 3 comments
Closed

Limit number of method/closure parameters rule #415

delebedev opened this issue Jan 25, 2016 · 3 comments
Labels
rule-request Requests for a new rules.

Comments

@delebedev
Copy link
Contributor

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
Copy link
Contributor

Interesting idea. Do you think this should or shouldn't count parameters with default values?

@delebedev
Copy link
Contributor Author

@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

@jpsim jpsim added the rule-request Requests for a new rules. label Jan 25, 2016
@scottrhoyt
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule-request Requests for a new rules.
Projects
None yet
Development

No branches or pull requests

3 participants