C# interview

Denis Koroskin 2korden at gmail.com
Tue Oct 7 03:36:25 PDT 2008


On Tue, 07 Oct 2008 05:55:30 +0400, Michel Fortin  
<michel.fortin at michelf.com> wrote:

> On 2008-10-06 09:11:41 -0400, "Denis Koroskin" <2korden at gmail.com> said:
>
>> char? <-> Nullable@(char)
>> char*? <-> Nullable@(char*)
>
> Ok, I think see your point.
>
> We only got different interpretations. Mine was that only pointers (and  
> object reference) could be made null, therfore, only pointers and object  
> references could be nullable, but wouldn't be by default.
>
> Your idea is that any type can be made nullable. For pointers and object  
> references, this would be represented by null pointers; for other types  
> it'd have to be some kind of struct containing that type and a boolean  
> null-indicator value. Is this correct?
>
>

Yes, although you don't have to use them.
See http://www.nwcpp.org/Downloads/2006/The_Power_of_None.ppt

> Although I don't dislike this idea, I think nullable value-types offer  
> much less value than nullable pointers and references. For one, making  
> value-types nullable isn't a solution for the problem at hand -- null  
> pointer errors (access violation, segmentation faults, etc.) -- because  
> value-types already don't have this problem. For two, it makes the type  
> memory layout bigger instead of simply allowing it to hold the special  
> zero value.
>

Agree, but who said that zero is illegal integer value? How do I know  
whether the variable is already initialized or not?

> That said, I'm not against nullable value-types. My opinion is that  
> perhaps the language could be kept simpler by only allowing pointer and  
> object references to be nullable, because that's where it matters the  
> most.
>

Yes, you rarely need use of them, and in most cases they are local  
variables created on stack so the cost is minimal.
That said, they are not crucial for the language, but it is better to have  
them for consistency with reference types.



More information about the Digitalmars-d mailing list