Is empty array null?

Steven Schveighoffer schveiguy at yahoo.com
Mon Mar 5 17:18:59 PST 2012


On Mon, 05 Mar 2012 20:00:12 -0500, bearophile <bearophileHUGS at lycos.com>  
wrote:

> Steven Schveighoffer:
>
>> D makes arrays as safe as possible, and as useful as possible.  The
>> pointer value itself is an implementation detail, and should rarely be
>> used to determine logic.
>
> D array design also leads to some traps, like forgetting to use "ref"  
> here:
>
> void append5andMore(int[] a) {
>     a ~= 5;
>     a.length++;
> }

Yes, but without these semi-value semantics, slices are not as nice.  It's  
all a matter of trade-offs.

I personally have learned to avoid these traps.

-Steve


More information about the Digitalmars-d-learn mailing list