Forbid dynamic arrays in boolean evaluation contexts

Phil Lavoie maidenphil at hotmail.com
Mon Mar 25 10:18:00 PDT 2013


On Monday, 25 March 2013 at 17:14:47 UTC, H. S. Teoh wrote:
> On Mon, Mar 25, 2013 at 08:46:42PM +0400, Dmitry Olshansky 
> wrote:
>> 25-Mar-2013 20:43, Phil Lavoie пишет:
>> >I do believe that, in any case, this form is best:
>> >if( arr !is null && !arr.empty )
>> >
>> 
>> Now write that one thousand times and count the typos.
> [...]
>
> What's wrong with just writing: if (arr.length > 0) ?  .length 
> will
> return 0 both when arr is null and when it's non-null but empty.
>
>
> T

Nothing is wrong with that apparently. I was not aware arr.length 
tolerated null slices. Does it keeps its behavior in unsafe or 
system mode?

Phil


More information about the Digitalmars-d mailing list