You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As opposed to named parameters, named arguments is about using the parameter name on the call site.
Named arguments enable you to specify an argument for a positional parameter by matching the argument with its name rather than with its position in the parameter list.
Example:
voidmain() {
final a =A(x:1, y:2);
final another =A(y:2, x:1);
}
classA {
finalint x;
finalint y;
A(this.x, this.y);
}
Rationale:
The decision to use named or positional arguments can be a decision the call site should make.
Private properties
voidmain() {
final a =A(x:1, y:2);
}
classA {
finalint _x;
finalint _y;
A(this._x, this._y);
}
I'm sure I have proposed something like this before, possibly as part of some other feature (I can't find an issue right now).
It's a nice idea which allows users to refer to parameters by name, when they have a name, even if they are not named parameters.
The risks are that the names are not really part of the function value, they're just metadata on the static function types.
You can't use those names in a dynamic invocation.
Any operation on types may affect the metadata. We'll have to specify precisely how it's propagated through all type operations (with Up and Down being the biggest risks, and Norm probably not mattering since it's only used at runtime).
It becomes a breaking change to change the name of a positional parameter. Even if you never intended it to be used as a parameter name in that way, there is no way to opt out. (Well, you can make it a private name, but that's ugly, and we don't want everybody making their positional parameters private just to not get trapped with a name that they want to change, effectively getting trapped with an ugly private name instead.)
Named argument
As opposed to named parameters, named arguments is about using the parameter name on the call site.
Named arguments enable you to specify an argument for a positional parameter by matching the argument with its name rather than with its position in the parameter list.
Example:
Rationale:
The decision to use named or positional arguments can be a decision the call site should make.
Private properties
Related:
Named argument shorthand
prefixing an argument variable with
:
uses the same name as the variable nameExample:
Related: Object spread shorthand
Syntax sugar
...Object
is used in a constructor / function call to unpack labels:...Object
unpack the labels with the intersection between the parameters name and the object getters name.Copies with null values
The last declaration of the field wins, allowing copying with null values (when the fields are not private).
The text was updated successfully, but these errors were encountered: