default constructors and implicit super() insertion

Graydon Hoare graydon at mozilla.com
Tue Jun 26 18:32:12 PDT 2007


Peter Hall wrote:

> Seems like we are talking about adding another new syntax to the
> language, that will be alien to existing JS and AS developers, not
> familiar with C++.

Sure, it's new syntax. So are many things here. The entire concept of a 
non-nullable type is going to be a bit new to developers who have never 
ventured outside AS and JS. ECMAScript is generally a hybrid language 
though, borrowing from a variety of languages, both 
functional/expression and OO/statement languages. The technique has seen 
good use elsewhere, though there are plenty of subtle variants to choose 
from. I personally like the form employed by Nice:

http://nice.sourceforge.net/manual.html#constructor

But we can quibble over syntax independently. Do you think nullable 
types are worthwhile?

> This syntax doesn't seem to add anything either. It's equivalent to
> enforcing that you initialize the properties in the constructor (as
> opposed to doing it in other functions that could be invoked by the
> constructor). But you could enforce that same restriction without the
> new syntax. I don't know much about compilers, but is it really too
> expensive to check that each non-nullable property has been assigned
> with a value inside the constructor body?

The committee's feeling was that definite-assignment analysis -- what 
you're describing -- is too expensive, especially for lightweight 
compilers. It might be that any lightweight compiler is actually going 
to run in standard mode all the time anyways, and we might not make 
standard mode obliged to detect failure-to-initialize-non-nullable until 
ctor execution time, in which case there's no "analysis", just a runtime 
bit. I do not have deep feelings either way, and I'm not sure whether we 
decided to support settings lists before or after our notions of strict 
and standard modes had fully formed.

Anyone want to chime in? I suspect a couple of the people with opinions 
are presently or shortly on vacation...

> BTW does anyone have any thoughts on my original questions?

Automatic inference of the default ctor signature and default super-call 
from the superclass would be fine by me. I'm not sure what other people 
think. It'd break AS code.

-graydon




More information about the Es4-discuss mailing list