F i L:

Walter Bright wrote:
3. Floating point values are default initialized to NaN.

This isn't a good feature, IMO. C# handles this much more conveniently

An alternative possibility is to:
1) Default initialize variables just as currently done in D, with 0s, NaNs, etc; 2) Where the compiler is certain a variable is read before any possible initialization, it generates a compile-time error;
3) Warnings for unused variables and unused last assignments.

Where the compiler is not sure, not able to tell, or sees there is one or more paths where the variable is initialized, it gives no errors, and eventually the code will use the default initialized values, as currently done in D.


The D compiler is already doing this a little, if you compile this with -O:

class Foo {
  void bar() {}
}
void main() {
  Foo f;
  f.bar();
}

You get at compile-time:
temp.d(6): Error: null dereference in function _Dmain


A side effect of those rules is that this code doesn't compile, and similarly lot of current D code:

class Foo {}
void main() {
  Foo f;
  assert(f is null);
}


Bye,
bearophile

Reply via email to