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

improve Dart constructor design #28322

Closed
vsmenon opened this issue Jan 10, 2017 · 6 comments
Closed

improve Dart constructor design #28322

vsmenon opened this issue Jan 10, 2017 · 6 comments
Labels
P2 A bug or feature request we're likely to work on web-dev-compiler

Comments

@vsmenon
Copy link
Member

vsmenon commented Jan 10, 2017

From @jmesserly on May 4, 2015 16:48

(Original context #51 and #162)

All Dart constructors are currently instance methods, as it's the only way to generate simple code with super. Once classes are finished in V8 (https://code.google.com/p/v8/issues/detail?id=3330) we can revisit constructors to see if there's a better pattern. I would really like to use real JS constructor whenever possible; currently only core.Object has a "real" constructor. The current pattern should basically work though, as long as we mixin the initializer logic any time we're extending a native type (currently just Object, but in the future, Custom Elements too).

However, I'm not sure it will interact well with strong mode in the future. Last I checked, "use strong" mode's preferred initialization order is backwards from Dart's (superclass fields first, instead of subclass fields first), so it's going to be tricky. Perhaps we can solve this with analysis to determine if initializers have side effects (hard in general, but perhaps doable for initializers, as they tend to be simple?) or a way programmers can simply tell us they don't care (because really, initializers shouldn't have side effects in a well designed program).

Copied from original issue: dart-archive/dev_compiler#163

@vsmenon
Copy link
Member Author

vsmenon commented Jan 10, 2017

From @jmesserly on May 5, 2015 16:36

#162 points out the current pattern is actually broken, if the named constructor has the same name as an inherited member. Unlike all other cases where member name conflicts are statically rejected, that one is allowed. Yet another nudge towards changing how named constructors work.

@vsmenon vsmenon added web-dev-compiler P2 A bug or feature request we're likely to work on labels Jan 10, 2017
@vsmenon
Copy link
Member Author

vsmenon commented Jan 10, 2017

From @jmesserly on April 27, 2016 0:48

CC @rakudrama who hit this looking at our (abysmal :) ) runtime performance.

@vsmenon
Copy link
Member Author

vsmenon commented Jan 10, 2017

From @jmesserly on April 27, 2016 0:49

Suspect the right fix here nowadays is just generate something uglier in JS if needed. Maybe we split out ctors and initializer methods.

@vsmenon
Copy link
Member Author

vsmenon commented Jan 10, 2017

From @jmesserly on April 27, 2016 16:27

FWIW, we could certainly change to spread/rest args and have the base Object constructor() jump to our initialize method which has a known name. I'm not sure that would help much, though. The initializer method was basically a door to get out of the (silly) ES6 constructor restrictions.

@vsmenon
Copy link
Member Author

vsmenon commented Jan 10, 2017

From @jmesserly on April 29, 2016 22:40

Taking a shot at this hmm, nothing jumped out as a great solution, going to leave for now

@jmesserly
Copy link

This was tackled: we now use ES5 constructors for better performance. Default constructor is called .new

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 A bug or feature request we're likely to work on web-dev-compiler
Projects
None yet
Development

No branches or pull requests

2 participants