This is a migrated thread and some comments may be shown as answers.

used literal argument is not named

3 Answers 224 Views
Code Analysis
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Tom
Top achievements
Rank 1
Tom asked on 28 Jul 2015, 04:41 PM

Hi,

 

Just upgraded to Q2 2015 SP1 (2015.2.724.2) in VS 2015

 Now I'm getting the warning above all over the place.

 code example:

        var searcher = new DirectorySearcher(root, string.Format(CultureInfo.InvariantCulture,

"(&(objectClass=user)({0}={1}))"
, attributeMapUsername, username));​

What is the fix?

thanks

Tom

 

3 Answers, 1 is accepted

Sort by
0
Najid Hanif
Top achievements
Rank 2
answered on 28 Jul 2015, 05:41 PM
I just ran into this as well. You can have JustCode ignore this in the options. See screen shot for where this is located.
0
Tom
Top achievements
Rank 1
answered on 28 Jul 2015, 06:39 PM
Thanks, I did find this way out. But I'm wondering what is the purpose of this warning?  What is the preferred code technique?
0
Nikolay Valchev
Telerik team
answered on 31 Jul 2015, 08:52 AM
Hello,

We added this warning for people who prefer to name all literal arguments. It is considered by some that it improves readability and makes the code more descriptive and understandable. Lets take this code for example:

SyntaxToken token = syntaxTree.GetTouchingToken(0, null, cancellationToken, true);


Without looking at or knowing the signature of GetTouchingToken, could you be sure what the literals stand for? Yes, the digit is predictable but the rest two literals might mean so many things. Let's look of the code when named arguments are used.

SyntaxToken token = syntaxTree.GetTouchingToken(position: 0,
                              condition: null,
                              cancellationToken : cancellationToken,
                              findInsideTrivia: true);


It looks way more understandable. Of course, this is a personal/team preference, we do not want to impose it as a better practice, hence there is a setting that disables the warning.

Regards,
Nikolay Valchev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Code Analysis
Asked by
Tom
Top achievements
Rank 1
Answers by
Najid Hanif
Top achievements
Rank 2
Tom
Top achievements
Rank 1
Nikolay Valchev
Telerik team
Share this question
or