Proposal: Require named arguments
See original GitHub issueSay we have a method or constructor with many parameters of the same type:
public Foo(int a, int b, int c, int d)
{
...
}
And creating an instance:
new Foo(
a: 1,
b: 2,
c: 3,
d: 4);
This comes up most often for constructors of immutable types.
The warning could show when the following criteria are met:
- More than 3 arguments.
- Each argument on their own row.
- At least two adjacent arguments are of the same type.
- Not in an expression tree.
Wrote it here if anyone wants to play with it. Think it is a good fit in StyleCop though.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:4
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Named arguments proposal
It's not possible to have a named parameter that is required to have a value passed to it. As per 1, they're all...
Read more >samuelgoto/proposal-named-parameters: An exploration of ...
An exploration of adding named parameters to JS. Contribute to samuelgoto/proposal-named-parameters development by creating an account on GitHub.
Read more >A proposal for named arguments for C++
This proposal allows calling existing functions with named arguments, without the author of the function having to "opt-in" to this in any way....
Read more >What happened to the named parameter proposal? : r/cpp
Named parameters makes the builder pattern redundant in most cases and lead to clearer code in my opinion. I am interested want happened...
Read more >Why we need named arguments in PHP
The main argument against named arguments — the PHP 8 puns continue — is that they would make maintaining open source software a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I would argue that the warning should not be fired when the argument name is equal to the name of the variable that is used as the argument:
This sort of “copies” the behaviour of ReSharper, ReSharper shows the argument name in the code when it is not specified and the variable used as argument does not have the same name as the argument.
💭 I wonder how helpful a “StyleCop Extras” project would be, where many of the code-style-related subjective rules that get requested could be developed.