null Vs [] return arrays

spir denis.spir at gmail.com
Fri Apr 1 04:36:14 PDT 2011


On 04/01/2011 12:38 PM, Regan Heath wrote:
> 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. :)

That's the way I understand this distinction. Unfortunately, D does not really 
allow this, by semantically treating both indifferently (eg one can put a new 
element into an null array).

Denis
-- 
_________________
vita es estrany
spir.wikidot.com



More information about the Digitalmars-d-learn mailing list