-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Meta-issue for discussion of the proposal to allow named arguments everywhere #30353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm constantly confused whether I should use a named or positional optional argument. I like the terseness of the latter sometimes, but it's a huge pain to refactor and deprecate later on, so I usually choose named: void doThing([bool someFlag = false]);
void doThing({bool someFlag = false}); My understand is that this proposal would simply allow: void doThing([bool someFlag = false]);
doThing(true);
doThing(someFlag: true); Is that correct? That makes it seem like "named" is just an alias for the tools (i.e. new frontend), and everything is actually a positional argument. I like this simplification from the perspective of understanding what a compiler will do at a user-level. Some downsides or questions I'd have:
Widget createWidget([
@Deprecated('This flag is no longer supported and will be removed')
bool someFlag = false,
@required String title,
List<Widget> children = const [],
]) If any user could use this function like
void printOnFailure(void Function(String message, {int times}) write); I guess I could write: printOnFailure(() => 'Bad, times = 10); Or: printOnFailure(() => 'Bad', 10); Is that correct? |
That's not correctly guessed. I have extended the initial message to make guessing less necessary :) |
Regarding this comment from @lrhn my understanding is that this proposal is to allow to write: m(a: 10, p1Value, b: false, p2Value) (named parameter anywhere) for fonction defined by void m(Object p1, Object p2, {int a, bool b}) |
How about void doThing(Object p1, Object p2); to be allowed both: doThing(x, y); and doThing(p1: x, p2: y); |
@JFixby, that's actually a different proposal, much closer to issue #30255, and Lasse already gave a very detailed response on why that idea has substantial software engineering costs; Arduin referred to the same comment above. This is a simpler proposal where named arguments must always be passed as named arguments, and positional arguments always positionally, but you can put the named arguments anywhere you want in the actual argument list, and the positions of the positional arguments are computed by not counting the named arguments along the way (so in |
My concern is only that when you change function declaration between void doThing( Object p1, Object p2 ); and void doThing( { Object p1, Object p2 } ); void doThing( [ Object p1, Object p2 ] ); void doThing( Object p1, { Object p2 } ); and so on. Then you have to go and fix each line calling this function, even if you didn't change anything in the callings from technical point of view: doThing(p1: x, p2: y); // is still the same call, right? |
Should I create a separated ticket for that? |
Note that we also have #15398 'Allow named function arguments anywhere in the argument list' |
Closing as dart-lang/language#1072 has landed |
Uh oh!
There was an error while loading. Please reload this page.
This issue is to provide a forum for community discussion and feedback related to the proposal to allow named arguments to appear at any position in an argument list.
That is, named arguments may appear before positional arguments when calling a function. Example:
This entry will be updated when a proposal is available.
cc @munificent @eernstg @floitschG @lrhn
The text was updated successfully, but these errors were encountered: