Skip to content

Limit number of method/closure parameters rule #415

Closed

Description

@delebedev

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)

Activity

  1. scottrhoyt commented on Jan 25, 2016

    @scottrhoyt
    Contributor

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

  2. delebedev commented on Jan 25, 2016

    @delebedev
    ContributorAuthor

    @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
  3. added
    rule-request
    on Jan 25, 2016
  4. scottrhoyt commented on Jan 26, 2016

    @scottrhoyt
    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.

  5. added a commit that references this issue on Jan 31, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    rule-request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions