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

Enhancement to assigning variables quickly via constructors #11707

Closed
DartBot opened this issue Jul 6, 2013 · 7 comments
Closed

Enhancement to assigning variables quickly via constructors #11707

DartBot opened this issue Jul 6, 2013 · 7 comments
Assignees
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Jul 6, 2013

This issue was originally filed by ayman.ga...@gmail.com


This is an enhancement type, can't find it in templates.

== current way of quick assigning properties via constructor :
class Person {
  String name;

  Person(this.name);

  String greet() => 'Hello, $name';
}

class Employee extends Person {
  num salary;

  Employee(String name, this.salary) : super(name);
}

== proposed way:

class Person {
  String name;

  Person(this.name);

  String greet() => 'Hello, $name';
}

class Employee extends Person {
  num salary;

  Employee(super.name, this.salary);
}

@iposva-google
Copy link
Contributor

Removed Type-Defect label.
Added Type-Enhancement, Area-Language, Triaged labels.

@gbracha
Copy link
Contributor

gbracha commented Aug 21, 2013

It seems a harmless bit of sugar.


Set owner to @gbracha.
Added this to the Later milestone.
Added Accepted label.

@kasperl
Copy link

kasperl commented Jul 10, 2014

Removed this from the Later milestone.
Added Oldschool-Milestone-Later label.

@kasperl
Copy link

kasperl commented Aug 4, 2014

Removed Oldschool-Milestone-Later label.

@DartBot
Copy link
Author

DartBot commented Jan 25, 2015

This comment was originally written by @kaendfinger


This would be another nice addition.

@DartBot
Copy link
Author

DartBot commented Jan 26, 2015

This comment was originally written by @seaneagan


I don't see how it could be sugar for calling a parent constructor because you wouldn't want changing the name of a positional constructor parameter to break subclasses, and if it assumes calling the same-named constructor of the superclass, then that probably prevents it from being used in many cases.

@DartBot DartBot added Type-Enhancement area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Jan 26, 2015
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed priority-unassigned labels Feb 29, 2016
@munificent
Copy link
Member

It's not clear to me what this is actually proposing.

If it sidesteps the superclass's constructor and assigns its field directly, that's bad. It violates the superclass's own encapsulation. A class should be able to ensure all instantiations go through its own constructors so it can enforce its preconditions and invariants.

If it is calling the superclass's constructor, it's not clear how it knows which constructor to call and which arguments to pass for what.

I'm going to go ahead and close this because I don't think we intend to take action on it. Though, for what it's worth, I have found myself wishing for something similar on occasion. Once you get used to this.x, it feels annoying to have to manually forward and type annotate the parameters for the superclass.

@munificent munificent added the closed-not-planned Closed as we don't intend to take action on the reported issue label Dec 19, 2016
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-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

6 participants