Fwd: Nullablity
Shijun He
hax.sfo at gmail.com
Fri Jun 23 06:46:25 PDT 2006
---------- Forwarded message ----------
From: Shijun He <hax.sfo at gmail.com>
Date: Jun 23, 2006 1:34 PM
Subject: Re: Nullablity
To: Graydon Hoare <graydon at mozilla.com>
On 6/23/06, Graydon Hoare <graydon at mozilla.com> wrote:
> Nicolas Cannasse wrote:
>
> > As for values initialization, it should be enforced by the compiler.
> > This can easily be done for member and local variables by using some
> > recursive flow algorithm.
>
> I know you're coming from the background of compiling large, highly
> structured programs, and I respect that perspective. I personally agree
> with what you've said here, in the context of a language *for my
> programming needs*.
>
> But I've also heard a credible argument during the design process: that
> the majority of JS code on the web is tiny little fragments, one liners,
> often fragments that only run zero or one times, and sometimes running
> on a cell phone. Keeping the "defaults" easy to compile is a priority
> for at least some of the language implementers. This means dataflow
> algorithms are unappealing: local expression-type inference is about all
> we want to pay for. We do not want to reimplement Java's definite
> assignment rules or similar.
There r 2 modes: strict and non-strict(what named 'standard' now, but
i don't like this name, maybe 'loose' will be better). So, if i want
to write a tiny code fragment, i can use non-strict mode or even back
to ES3.
Strict mode should help coder to eliminiate all NullPointerException.
About non-strict mode, any access to uninitializd non-nullable var
will cause UninitializedError.
I think there is no need to introduce C++ initializer. In strict mode,
compiler could ensure non-nullable member will be initialize in
constructor, in non-strict mode, nothing happend until uninitializd
non-nullable property being accessed, result in UninitializedError.
And I suggest that we can introduce default function for default value
of non-nullable type.
class Complex {
static const zero:Complex = new Complex(0, 0);
function default() { return zero; }
function Complex(a, b) {...}
...
}
var c:Complex;
assert (c == new Complex(0, 0));
Here a another simpler syntax i suggested:
class Complex {
static const zero = new(0, 0); // for constant, there is no need to
declare type
default() { return zero; } // function keyword can be omitted in
class definition
new(a, b) {...} // use 'new' instead of the class identifier, and
we could allow such usage: c = Complex.new(0, 0);
...
}
>
> We've talked through many alternatives, and I agree that the topic is
> not yet exhausted. Some syntactically distinct form that covers for the
> same task is possible. We've discussed C++-style initializer syntax for
> example, or ML-style construction-from-a-set-of-expressions. I'm sure
> there are other potential options, but we must keep the tradeoffs in mind.
>
> -graydon
> _______________________________________________
> Es4-discuss mailing list
> Es4-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es4-discuss
>
More information about the Es4-discuss
mailing list