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
Dart functions currently can have only either optional named parameters or optional positional parameters, but not both.
While developing libraries repeatedly run into cases where this restriction gets in the way of the signature we want.
It would be preferable if you could have both kinds of parameters on the same function.
The only syntax change necessary is to the declaration of functions. The call syntax is unaffected, and so is noSuchMethod/Function.apply.
nbro, kasperpeulen, samihaddad, skybur, joe776 and 210 moresigurdm, DrSensor, nythrox, mateusfccp, PopeJuliusII and 21 more
2 separate optional parameters within the same declaration, one named, one positional
allowing a single optional parameter to be both named and positional
The former could be solved by non-overlapping [] and {}. If overlapping [] and {} are allowed, then would have to decide whether to allow both {[ and [{ as well as }] and ]].
It is asking for non-overlapping [] and {}.
Examples:
new List([length = 0], {fill: null});
Stream.subscribe([onData], {onError, onDone})
new Date(year, [month, ...., milliseconds], {isUtc: false})
Sounds perfect! The only other thing I would change (also mentioned in issue dart-lang/sdk#6496) is to use = instead of : for named positional default values:
new List([length = 0], {fill = null});
The = to default positional optionals doesn't mimic call site syntax, so why does the named positional default syntax try to? I think it's more importatnt to be consistent between how to default optional parameters regardless of whether they are named or positional.
Activity
floitschG commentedon Nov 30, 2012
This issue is related to issue dart-lang/sdk#6496, but asks for less.
DartBot commentedon Nov 30, 2012
This comment was originally written by @seaneagan
Is this asking for:
The former could be solved by non-overlapping [] and {}. If overlapping [] and {} are allowed, then would have to decide whether to allow both {[ and [{ as well as }] and ]].
floitschG commentedon Nov 30, 2012
It is asking for non-overlapping [] and {}.
Examples:
new List([length = 0], {fill: null});
Stream.subscribe([onData], {onError, onDone})
new Date(year, [month, ...., milliseconds], {isUtc: false})
gbracha commentedon Nov 30, 2012
Added this to the Later milestone.
Added Accepted label.
DartBot commentedon Dec 1, 2012
This comment was originally written by @seaneagan
Sounds perfect! The only other thing I would change (also mentioned in issue dart-lang/sdk#6496) is to use = instead of : for named positional default values:
new List([length = 0], {fill = null});
The = to default positional optionals doesn't mimic call site syntax, so why does the named positional default syntax try to? I think it's more importatnt to be consistent between how to default optional parameters regardless of whether they are named or positional.
DartBot commentedon Feb 25, 2014
This comment was originally written by @rbishop-bah
Related: Issue dart-lang/sdk#17101
kasperl commentedon Jul 10, 2014
Removed this from the Later milestone.
Added Oldschool-Milestone-Later label.
kasperl commentedon Aug 4, 2014
Removed Oldschool-Milestone-Later label.
gbracha commentedon Aug 27, 2014
Issue dart-lang/sdk#17101 has been merged into this issue.
lrhn commentedon Oct 28, 2014
Marked this as blocking dart-lang/sdk#21406.
donny-dont commentedon Sep 9, 2015
Since 2.0 is thinking of some drastic changes is there any way the more extreme do like C#, Python, of dart-lang/sdk#6496 can be revisited.
@gbracha would a DEP be required for this?
seaneagan commentedon Sep 10, 2015
@donny-dont if this issue is fixed then we will be able to do:
Then if there is really a need to allow parameters to be both named and positional, we could further allow something like this syntax:
But personally, I think that creates unnecessarily bloated API surface.
bobjackman commentedon Sep 29, 2017
Any guesses when this might get implemented?
69 remaining items