Introducing Nullable Reference Types in C#. Is there hope for D, too?

Ola Fosheim Grøstad ola.fosheim.grostad+dlang at gmail.com
Mon Nov 20 10:53:04 UTC 2017


On Monday, 20 November 2017 at 10:07:08 UTC, Atila Neves wrote:
> The problem with null as seen in C++/Java/D is that it's a 
> magical value that different types may have. It breaks the type 
> system.

Not sure if it breaks the type system, but it would be cleaner to 
construct types with null "int|null", "float|null" etc, but then 
you would have a high level language and there are many NaN 
values (two semantic Nan values, but many encodings that might be 
used for conveying extra information)

>> assuming a value was not null. But it wouldn't have been 
>> better with non-nullable types, since the logic error would 
>> have been hidden and may have been much, much harder to 
>> recognize and track down.
>
> No, it would have been a compile-time error instead.

Yes, but you don't need non-nullable types, you could have 
subtyping of nullable types instead. For floats that would be 
very useful. E.g. constraint a float to the range [0.0, 1.0> or 
integers or not-infinity/not-nan etc.



More information about the Digitalmars-d mailing list