Description
This issue was originally filed by [email protected]
Dart introduces additional syntax to support positional and named arguments. This goes against various other languages that support optional and positional arguments where no additional syntatic sugar is needed, and creates an additional hurdle to learn the language.
In C# arguments can be passed by name or by position. As an example from http://msdn.microsoft.com/en-us/library/dd264739.aspx, If you had the following method
static int CalculateBMI(int weight, int height)
It could be invoked in the following ways
CalculateBMI(123, 64);
CalculateBMI(weight: 123, height: 64);
CalculateBMI(height: 64, weight: 123);
CalculateBMI(123, height: 64);
However it cannot be invoked like this, as positional arguments cannot follow a named argument
//CalculateBMI(weight: 123, 64);
For optional arguments the same rules apply
static public void ExampleMethod(
int required,
string optionalstr = "default string",
int optionalint = 10)
ExampleMethod(3, optionalint: 4);
ExampleMethod(3, "a string", 4);
However it can not be invoked positionally without specifying all the values up to that point
//ExampleMethod(3, ,4);
So in C# all methods can be invoked with either named or positional arguments. No additional syntax is required. Optional parameters have their values specified by using assignment in the declaration.
Dart syntax for named/optional parameters is different and provides no additional gain. See http://rosettacode.org/wiki/Named_parameters for examples on other language's implementation, such as Python which provides a similar implementation.