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
5 tasks done
floitschG opened this issue Oct 10, 2016 · 5 comments
Closed
5 tasks done

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

floitschG opened this issue Oct 10, 2016 · 5 comments
Labels
area-language New language issues should be filed at https://github.com/dart-lang/language
Milestone

Comments

@floitschG
Copy link
Contributor

floitschG 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 the area-language New language issues should be filed at https://github.com/dart-lang/language label Oct 10, 2016
@floitschG floitschG added this to the 1.50 milestone Oct 10, 2016
@kasperpeulen
Copy link

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
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 as completed Oct 20, 2016
@lrhn
Copy link
Member

lrhn commented Oct 20, 2016

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

@munificent
Copy link
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
Copy link
Member

lrhn commented Oct 21, 2016

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

@lyrachord
Copy link

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
Labels
area-language New language issues should be filed at https://github.com/dart-lang/language
Projects
None yet
Development

No branches or pull requests

5 participants