default constructors and implicit super() insertion

Sho Kuwamoto skuwamot at
Tue Jun 26 16:43:39 PDT 2007

Just curious...

In modern compilers, can't the compiler issue an error if the
non-nullable member was (a) not initialized in the constructor, or (b)
used before it was set?

I've always hated the C++-style member initialization syntax and it
seems like a shame to add it if it could be avoided. Shouldn't it also
be a goal to make sure that ES4 is less baroque and easier to learn than

Just my 2c.


-----Original Message-----
From: es4-discuss-bounces at
[mailto:es4-discuss-bounces at] On Behalf Of Brendan Eich
Sent: Friday, June 22, 2007 6:41 PM
To: P T Withington
Cc: Peter Hall; es4-discuss
Subject: Re: default constructors and implicit super() insertion

On Jun 22, 2007, at 3:11 PM, P T Withington wrote:

> I've always wondered what the point of carrying over C++'s constructor

> syntax was.

Ignoring the old pre-historic ES4 spec cited by Peter, I have to
apologize again for:

being out of date. The syntax we've settled on is not C++-like to that
degree. It looks like this:

class C {
     var x : Object!
     var y : int

     function C(initialX : Object!, initialY : int)
       : x = initialX, y = initialY

A few points:

1. The purpose of this syntax is to ensure that class vars of non-
nullable type are known to be initialized, with no chance for an
uninitialized error that would be the dual of the null pointer exception
(the exception that we hope to avoid via non-nullable types), while not
requiring definite assignment or any other such analysis.

2. The = assignment operator is used as elsewhere, to allow
destructuring assignments to set non-nullable vars. To avoid confusion
with other kinds of initialization, we call these assignment expressions
in the head of the constructor "settings", "class settings", or
"constructor settings".

3. The scope chain for the right-hand side of each = includes the formal
parameter names but not the new |this| object, while the scope chain for
the left-hand side includes |this| but not the formal parameters. So the
above could be simplified:

class C {
     var x : Object!
     var y : int

     function C(x : Object!, y : int) : x = x, y = y

4. An alternative syntax inspired by OCaml was:

class C(ax : Object!, ay : int) {
     var x : Object! = ax;
     var y : int = ay;

     function C {

but this is too far from existing syntax and scoping (see http://

Anyway, settings are implemented in the reference implementation
available at -- try them out and file bugs
at the trac if need be (look for existing tickets on the same issue
first). Thanks,


Es4-discuss mailing list
Es4-discuss at

More information about the Es4-discuss mailing list