JustCode C# method - literal argument highlighting

10 posts, 0 answers
  1. Tomica
    Tomica avatar
    147 posts
    Member since:
    Apr 2008

    Posted 02 Aug 2015 Link to this post

        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.

     

     

  2. Svetlozar
    Admin
    Svetlozar avatar
    269 posts

    Posted 05 Aug 2015 Link to this post

    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
  3. DevCraft banner
  4. Tomica
    Tomica avatar
    147 posts
    Member since:
    Apr 2008

    Posted 16 Aug 2015 in reply to Svetlozar Link to this post

    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.

  5. Svetlozar
    Admin
    Svetlozar avatar
    269 posts

    Posted 19 Aug 2015 Link to this post

    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
  6. PrairieNerd
    PrairieNerd avatar
    1 posts
    Member since:
    Jan 2016

    Posted 19 Jan in reply to Svetlozar Link to this post

    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?

  7. Nikolay Valchev
    Admin
    Nikolay Valchev avatar
    72 posts

    Posted 22 Jan Link to this post

    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
  8. JeffSM
    JeffSM avatar
    11 posts
    Member since:
    May 2014

    Posted 03 Mar Link to this post

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

     

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

  9. Nikolay Valchev
    Admin
    Nikolay Valchev avatar
    72 posts

    Posted 04 Mar Link to this post

    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
  10. Bernard
    Bernard avatar
    2 posts
    Member since:
    Jun 2014

    Posted 10 Mar Link to this post

    is there a way to tell Just Code to fix all instances of those literal argument warnings in my code? 
  11. Svetlozar
    Admin
    Svetlozar avatar
    269 posts

    Posted 15 Mar Link to this post

    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
Back to Top
DevCraft banner