null and type safety

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Nov 4 10:48:54 PST 2008


Thomas Leonard wrote:
> On Mon, 03 Nov 2008 17:04:48 -0500, bearophile wrote:
> 
>> Brendan Miller:
>>> Null is a holdover from C and has no place in a typesafe language.<
>> In a (system) language I want to be able to create tree data structures
>> that contain a cargo plus true pointers, and those pointers to structs
>> can be null in leaves. Having a safe language is good, but I want 1
>> language that gives me sharp tools too.
>>
>>> I'm looking through the D docs, that are a little sparse, but I'm not
>>> seeing any references to pointers that can't be nulled.<
>> You may like the Delight language (it compiles to D2):
>> http://delight.sourceforge.net/null.html
> 
> Note that the maybe types in Delight are independent of the syntax 
> changes (apart from the ? type annotation) and you could easily enable 
> them when compiling D code too (basically, just remove the code that 
> disables this feature when it detects it's compiling D syntax source).
> 
> The basic problem is that it's hard to integrate a language with non-
> nullable types with libraries written without them (e.g. when auto-
> generating bindings with BCD). This would likely be a big problem for D, 
> since integrating with existing C and C++ code is a major feature.

It could be done if non-nullable pointers/references would be allowed in 
addition to nullable ones.

A note however - although I agree it's nice to have non-nullable types, 
the argument is a bit overstated as type safety has little to do with 
it. Null checks are easy and cheap to check for deterministically.


Andrei



More information about the Digitalmars-d mailing list