Null references (oh no, not again!)

Walter Bright newshound1 at digitalmars.com
Wed Mar 4 12:30:02 PST 2009


Nick Sabalausky wrote:
> As far as the SafeInt-style proposal, the problem I see with it is that the 
> need vs lack-of-need for overflow checks tends to be based more on what 
> you're doing with the variables rather than the actual variables themselves. 
> (Plus, weren't you just saying in the null/nonnull discussion that you 
> didn't want more variations on types?)

This would be the user's choice. Those that don't care for it, needn't 
use it. That's the advantage of the SafeInt class.


>> Global switches that change the behavior of the language are bad, bad 
>> ideas. It makes code unverifiable and hence untrustable.
> 
> Aren't you already doing that with things like bounds checking? I've been 
> under the impression that, when built with "-release", an out-of-bounds 
> access will result in undefined behavior, instead of an exception/assert, 
> just as in C.

In Java, you can rely on bounds checking to always be on, so you could, 
for example:

try
{
    for (int i = 0; i; i++)
        array[i] = ...
}
catch (ArrayBoundsException a)
{
}

which is perfectly legitimate code in Java. It is dead wrong in D, 
because the language behavior is defined to not necessarily throw such 
exceptions.

With overflow, there are legitimate uses of overflow arithmetic. You'd 
be hard pressed to make a statement like "overflow arithmetic is illegal 
in D" and have a useful systems programming language.



More information about the Digitalmars-d mailing list