On 05/19/2013 03:20 AM, Walter Bright wrote:
On 5/18/2013 5:23 PM, deadalnix wrote:
...
People go for the shortest path. You end up having nullable everywhere.
Experience have been a countless amount of time in bazillion programming
languages. But it is probably too late to fix this in D anyway.

I know that some languages have a special syntax for non-null pointers.

The saner ones have special syntax for _nullable_ types.

I disliked this solution for D because non-nullable pointers are just
one instance of creating a type with a limited set of values.

I think this is the wrong direction of approaching the problem.

D-style nullable references are an example of adding a value to a type whose typing judgements are invalid for that value:

class C{ void foo(){ ... }

void main(){
    typeof(null) a;
    a.foo(); // compile-time error
    C c = a;
    c.foo(); // segmentation fault
}

null is not a C, as it does not provide a C.foo method.

Why not go for a general solution?

You may want a type that has more than one special value. Why have language support for exactly one special value? In any case, why have unsound type checking for the sake of special values?

Why not create a mechanism where a type can be defined that can only consist of 
prime numbers, for example?

There are programming languages that allow this.

Why not ranged integer types?

Reply via email to