I find this feature "named arguments" from C# to be really weird because I see two flaws from it. The book says "named arguments give you the "ability to pass arguments in any order".
Two flaws I think is a problem for this C# feature:
It violates "information hiding" in computer science. (i.e.: the end user using the method needs to know the parameter name and data type to make use of the feature.) Coming from a Java background, this is weird. Why expose parameter names to the end of the user?
It is prone to ambiguity which can lead to bugs. (The programmer needs to do extra thinking and problems can creep up when the programmer wind up writing methods that use the same method name(aka overloading methods"). You will always get a "call is ambiguous when you have two methods with same name with the same parameters for each other even if the other method has a extra parameters with different data types. The only fix I can think of is to make the data type a "mandatory parameter" aka a parameter without a default value so the compiler does not get confused. But then this fix is only a bandage solution to leads to another worst case scenario (see below)
Do people in the industry even use this concept to this day? If so, why break the two rules to be given the "ability to pass arguments in any order when calling the method"?
TLDR: An Example to bring clarity to what I am talking about by introducing a possible worst case scenario(the compiler chose the wrong method call... despite resemblance of the two methods):
namespace ConsoleApplication1
{
class Venusaur
{
static void Main(string[] args)
{
new Venusaur().optMethod(fourth: "s");
}
public void optMethod( string third , string fourth = "hello", int fifth = 23, string two = "w")
{
// what if I wanted this method to run instead of the method below me
Console.WriteLine("did not execute");
}
public void optMethod(string third = "Byte", string fourth = "hello", int fifth = 4)
{
// But this method ran instead
Console.WriteLine("run");
}
}
}
I find your first argument completely specious. Like it or not the names of parameters are part of each method's semantics, particularly for abstract classes and methods that will be overridden in subclasses. The names of the parameters are a key signalling to users of a method on the semantics of that method, and of each parameters role in that semantics. Further it is essential for understanding of the semantics throughout the class hierarchy that parameter names be consistent, and not subject to the whims of individual programmers at each level.
Your second argument I find completely unintelligible. If you actually have a valid point here I suggest you rewrite this to achieve greater clarity.
That said, I rarely use named parameters in my method calls; the exception being for methods that accept more than two consecutive parameters of the same type. In this case I like to name them so that I, as the future reader of the code, can in fact decipher the method's use without having to constantly hover to see the intelli-sense.