sonar-delphi icon indicating copy to clipboard operation
sonar-delphi copied to clipboard

New rule: Methods should not have too many default parameters

Open fourls opened this issue 2 years ago • 1 comments

Prerequisites

  • [X] This rule has not already been suggested.
  • [X] This should be a new rule, not an improvement to an existing rule.
  • [X] This rule would be generally useful, not specific to my code or setup.

Suggested rule title

Methods should not have too many default parameters

Rule description

This rule would identify methods with more than a configured maximum number of default parameters. This would be a user-configurable property.

Rationale

Default parameters can be useful in cases when there is a sensible default value. They can, however, damage API interfaces when used to make a method's behaviour overly configurable - a method with too many default parameters is confusing, unpredictable at a glance, unintuitive to use, and likely overloaded in functionality.

Using multiple methods, method overloads, or configuration objects would be a more maintainable approach and would keep the API cleaner.

fourls avatar Nov 02 '23 02:11 fourls

This is a good one, thanks! Should also be relatively easy to implement.

cirras avatar Nov 14 '23 04:11 cirras