Skip to content
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

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

Closed
floitschG opened this issue Oct 10, 2016 · 5 comments

Comments

@floitschG
Copy link
Contributor

commented Oct 10, 2016

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 comment has been minimized.

Copy link

commented Oct 11, 2016

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

screen shot 2016-10-11 at 09 57 59

lrhn added a commit that referenced this issue Oct 14, 2016
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 .

@lrhn lrhn closed this Oct 20, 2016

@lrhn

This comment has been minimized.

Copy link
Member

commented Oct 20, 2016

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

@munificent

This comment has been minimized.

Copy link
Member

commented Oct 20, 2016

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

This comment has been minimized.

Copy link
Member

commented Oct 21, 2016

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

@lyrachord

This comment has been minimized.

Copy link

commented Mar 24, 2017

OK, you do, I do not. It's the life. 👎

= should just be the assignment symbol.
There is no semantics between the default value with name and the name.
JS version is not brilliant reason for this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.