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

JustCode C# method - literal argument highlighting

9 Answers 263 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.
Tomica
Top achievements
Rank 2
Tomica asked on 02 Aug 2015, 05:31 PM

    I am new to C# as of last week, but have been a heavy user of JustCode with VB.

 I think this is a very simple newbie question, not a technical issue.

 In the attached file you will see a code snippet for a method call where the first two arguments are highlighted in green squiggles "the used literal argument is not named".

As far as I know, C# works just fine with this call and I see no need to explicitly name each argument.

 How would I go about suppressing these spurious warnings?

 

Software: VS 2015 Pro, ASP.NET.AJAX Q2, JustCode 2015.2.724.

 

 

9 Answers, 1 is accepted

Sort by
0
Svetlozar
Telerik team
answered on 05 Aug 2015, 04:01 PM
Hi Thomas,

We made that warning for a widely used convention here at Telerik. We tend to use named arguments when the argument is true, false, null or "some string", because it increases the readability. The named argument doesn't change the produced code, it is just readability improvement (we highly appreciate). If you don't like it you can disable it from JustCode Options | Code Analysis | Problems | C# | The used literal argument is not named. On a side note, we will improve that as currently we warn for string literals in string.Format, Console.WriteLine, etc, where the parameter is known. As it is hard to qualify if a string literal brings parameter readability we will most probably go with a set of methods that we need to disable the warning for.


Regards,
Svetlozar
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
0
Tomica
Top achievements
Rank 2
answered on 16 Aug 2015, 04:11 PM

Thank you, the suggested solution works for me.

 

And after your excellent explanation, I understand why these parameters were flagged in the first place. As the sole developer for my projects, writing 100% of the code, I usually know what each parameter means (by design) but for others, use of named arguments is probably a good idea.

0
Svetlozar
Telerik team
answered on 19 Aug 2015, 02:17 PM
Hi,

Thank you for the follow-up, we really appreciate it! If you have other questions, please don't hesitate to write back.

Regards,
Svetlozar
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
0
PrairieNerd
Top achievements
Rank 1
answered on 20 Jan 2016, 02:33 AM

Understand the motivation for 'encouraging' fully qualified class paths... no objections there.  The problem I have with the current build of the Telerik suite in the context of VS Community 2015 - why would anyone ever use anything else?

is that the 'usual solution' to these warnings (everything still builds and runs fine) is to turn off inspection under 'Just Code'.  As of my recent rebuild / reinstall of VS2015C that option is no longer available for unknown reasons (see attached screenshot).  Any notions on why my Tools>Options>JustCode no longer gives atomic settings options, merely a 'turn off' or 'turn on' switch option?

0
Nikolay Valchev
Telerik team
answered on 22 Jan 2016, 03:38 PM
Hello,

Apart from 'Disable', JustCode has never had any options located under Visual Studio's Tools | Options | JustCode. Instead, you can find all settings at JustCode | Options. As for the warning settings, you are able to manage their behavior at JustCode | Options | Code Analysis | Problems | <desired language> and mark the problem as Error/Warning/Not a problem.

Best 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
0
JeffSM
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 03 Mar 2016, 06:13 PM

According this post and after test the code, the named argument make the code slower.

 

http://www.dotnetperls.com/named-parameters

0
Nikolay Valchev
Telerik team
answered on 04 Mar 2016, 02:23 PM
Hello,

Thank you for the information!
With the new C# compiler (powered by Roslyn), I believe this behavior should have been gone as the IL code produced by compiling the C# code is the same for both of the method invocations.
Old C# compilation to IL:
    .method private hidebysig static void Method1 () cil managed 
    {
        .locals init (
            [0] bool CS$0$0000
        )

        IL_0000: ldc.i4.1
        IL_0001: stloc.0
        IL_0002: ldc.i4.1
        IL_0003: ldstr "Perl"
        IL_0008: ldloc.0
        IL_0009: call void ConsoleApplication1.Program::Method3(int32,  string,  bool)
        IL_000e: ret
    }

    .method private hidebysig static void Method2 () cil managed 
    {
        IL_0000: ldc.i4.1
        IL_0001: ldstr "Perl"
        IL_0006: ldc.i4.1
        IL_0007: call void ConsoleApplication1.Program::Method3(int32,  string,  bool)
        IL_000c: ret
    }

New C# compilation to IL:
    .method private hidebysig static void Method1 () cil managed 
    {
        IL_0000: ldc.i4.1
        IL_0001: ldstr "Perl"
        IL_0006: ldc.i4.1
        IL_0007: call void ConsoleApplication1.Program::Method3(int32,  string,  bool)
        IL_000c: ret
    }

    .method private hidebysig static void Method2 () cil managed 
    {
        IL_0000: ldc.i4.1
        IL_0001: ldstr "Perl"
        IL_0006: ldc.i4.1
        IL_0007: call void ConsoleApplication1.Program::Method3(int32,  string,  bool)
        IL_000c: ret
    }

Also when you build the project (with the previous compiler) with Relase configuration further optimizations are made and the execution time differentce between both of the methods is even less. Furthermore, regardless of the build configuration, this time difference (on my machine) is less than a half of a nanosecond for 100,000,000 invocations of the methods.
Anyway, if you find it better to miss the named arguments when invoking a method, you are able to turn of the warning, so it stops bothering you.
 
Best 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
0
Bernard
Top achievements
Rank 2
answered on 10 Mar 2016, 07:38 PM
is there a way to tell Just Code to fix all instances of those literal argument warnings in my code? 
0
Svetlozar
Telerik team
answered on 15 Mar 2016, 04:10 PM
Hi,

Thank you for the great question! Currently - no, you can't, but that would be a great improvement.

That warning is already implemented as a Roslyn extension and we can improve it so you can fix all occurrences in a document/project/solution (like Remove unnecessary usings). I added it to our backlog.

Regards,
Svetlozar
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
Tomica
Top achievements
Rank 2
Answers by
Svetlozar
Telerik team
Tomica
Top achievements
Rank 2
PrairieNerd
Top achievements
Rank 1
Nikolay Valchev
Telerik team
JeffSM
Top achievements
Rank 2
Iron
Veteran
Iron
Bernard
Top achievements
Rank 2
Share this question
or