null Vs [] return arrays

Regan Heath regan at netmail.co.nz
Fri Apr 1 03:38:56 PDT 2011


On Mon, 28 Mar 2011 17:54:29 +0100, bearophile <bearophileHUGS at lycps.com>  
wrote:
> Steven Schveighoffer:
>
>> So essentially, you are getting the same thing, but using [] is slower.
>
> It seems I was right then, thank you and Kagamin for the answers.

This may be slightly OT but I just wanted to raise the point that  
conceptually it's nice to be able to express (exists but is empty) and  
(does not exist).  Pointers/references have null as a (does not exist)  
"value" and this is incredibly useful.  Try doing the same thing with  
'int' .. it requires you either use int* or pass an additional boolean to  
indicate existence.. yuck.

I'd suggest if someone types '[]' they mean (exists but is empty) and if  
they type 'null' they mean (does not exist) and they may be relying on the  
.ptr value to differentiate these cases, which is useful.  If you're not  
interested in the difference, and you need performance, you simply use  
'null'.  Everybody is happy. :)

R


More information about the Digitalmars-d-learn mailing list