Allow `=` as separator for named parameter default value. #27559

Closed
floitschG opened this Issue Oct 10, 2016 · 4 comments

Projects

None yet

4 participants

@floitschG
Member
floitschG commented Oct 10, 2016 edited

We have foo([x = 42]) and foo({x: 42}) as the ways to specify default values for parameters.

That means that changing your function from a positional parameter to a named parameter is not just changing the [] to {}, you also have to change = to : - but it still means exactly the same thing (default value). This breaks the rule about similar things having similar syntax.

Even without changing from one type of parameter to another, I still regularly write = for named parameters. There is simply nothing to remind me that it's not =.

It might be cute that it 1) looks like a map or 2) looks like how the function is called, but the former is only true in trivial cases and the latter isn't helping anyway - it's not like positional parameter default values looks like arguments in a function call.

@floitschG floitschG added this to the 1.50 milestone Oct 10, 2016
@kasperpeulen

This is also how named default parameters are done in ES2015:

screen shot 2016-10-11 at 09 57 59

@lrhn lrhn added a commit that referenced this issue Oct 14, 2016
@lrhn lrhn Add `=` as default-value separator for named parameters.
Fixes issue #27559.

BUG= http://dartbug.com/27559
R=asiva@google.com, eernst@google.com, floitsch@google.com, sigmund@google.com

Review URL: https://codereview.chromium.org/2411633002 .
efb9a12
@lrhn lrhn closed this Oct 20, 2016
@lrhn
Member
lrhn commented Oct 20, 2016

(Closing this, assuming the "intellij" checkmark is correct, the remaining ones were fixed by the same CL).

@munificent
Member

Magnificent! If only all language features could be implemented in one giant commit!

You should also update the CHANGELOG and otherwise let people know that this change exists. 🎉

@lrhn
Member
lrhn commented Oct 21, 2016

Changelog was ac76d3e
About letting people know ... probably a good idea :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment