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
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
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.
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
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?
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
According this post and after test the code, the named argument make the code slower.
http://www.dotnetperls.com/named-parameters
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.
Nikolay Valchev
Telerik
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