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

Constructors: let me access instance fields in initializer expressions if they have been set in an initializing formal #4181

Closed
kevmoo opened this issue Jul 23, 2012 · 5 comments
Assignees
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-duplicate Closed in favor of an existing report type-enhancement A request for a change that isn't a bug

Comments

@kevmoo
Copy link
Member

kevmoo commented Jul 23, 2012

This is okay

QrCode(int typeNumber, this.errorCorrectLevel)
  : this.typeNumber = typeNumber,
    moduleCount = typeNumber * 4 + 17 { ...

This is currently an error, but it'd be great if it worked.

QrCode(this.typeNumber, this.errorCorrectLevel)
  : moduleCount = typeNumber * 4 + 17 { ...

A nit, but nice to have.

@DartBot
Copy link

DartBot commented Jul 23, 2012

This comment was originally written by ladicek@gmail.com


Can someone even count how many bugs asking for this has already been opened and then closed as WontFix?

@kevmoo
Copy link
Member Author

kevmoo commented Jul 23, 2012

...and my bad for not searching for existing bugs on this issue.

My apologies...for the dupe, not for wanting this :-)

@DartBot
Copy link

DartBot commented Jul 23, 2012

This comment was originally written by ladicek@gmail.com


I'd love to have this too. I wouldn't worry about dupes (at least in this case), it's a clear sign that a lot of people want this.

Gilad says: if the sugar doesn't do what you want, don't use the sugar. Well... we want more sugar :-)

Specifically (pun intended), I'd love to have the word "not" deleted from this sentence "Using an initializing formal this.id in a formal parameter list does not introduce a formal parameter name into the scope of the constructor." in the chapter 7.5.1 of the spec.

@dgrove
Copy link
Contributor

dgrove commented Jul 24, 2012

Set owner to @gbracha.
Removed Type-Defect label.
Added Type-Enhancement, Area-Language, Triaged labels.

@gbracha
Copy link
Contributor

gbracha commented Jul 24, 2012

Here are some things I wish people would understand:

  1. Features are not free. Every addition costs something, both in terms of its own design and implementation, and, often more significantly, in terms of opportunity cost. The time we spend on issues like this comes at the direct expense of addressing more significant problems.

  2. Syntactic sugar is not a net win. The history of programming languages has shown this time and again.

  3. It is just common courtesy to check if a feature request already exists. But no worries, I found one of the related bugs to list as as duplicate.

  4. Being popular is nice, but that doesn't make it good (case in point: Javascript). In particular, the fact that a feature request is popular does not mean it's the right thing to do. I'm sorry, but this is a case in point. As I've explained repeatedly, the initial sugar had a great power-to-weight ratio: it's very simple, and it handles a very common situation. Leave it at that.


    Added Duplicate label.
    Marked as being merged into Shorthand constructor this.x parameters prohibit access to x in initializer list #1970.

@kevmoo kevmoo added Type-Enhancement area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-duplicate Closed in favor of an existing report labels Jul 24, 2012
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed type-enhancement labels Mar 1, 2016
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-duplicate Closed in favor of an existing report type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

4 participants