[:] as empty associative array literal, plus warning for null

Regan Heath regan at netmail.co.nz
Thu Jul 4 08:06:57 PDT 2013


On Thu, 04 Jul 2013 15:11:49 +0100, monarch_dodra <monarchdodra at gmail.com>  
wrote:

> On Thursday, 4 July 2013 at 13:32:25 UTC, Steven Schveighoffer wrote:
>>> Indeed.  IMO if(arr) should mean if(arr.ptr) .. and I thought it did..  
>>> or did this change at some point?
>>
>> No, it should mean if(arr.length).
>
> *I* think it should simply mean compilation error. There is, arguably, a  
> "big" difference between null and empty:
>
> ...
>
> IMO, you should have to state which you want. Making arbitrary choices  
> for the user in the face of ambiguity is evil.

That's another option, but I for one would be annoyed by this.

I would also argue that it's not ambiguous, if(x) has always meant  
"compare x with 0" (for me / in C style languages), which in this case  
means comparing the array reference to null, not comparing the array  
length to 0.

That is.. if array references are really reference types.  I which case  
they should obey the same rules/behaviour.

Imagine you had a class Array.

Array a = null;
if (a) // should compare the reference a to 0, not a.length to 0, right?

R

-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/


More information about the Digitalmars-d mailing list