if(arr) now a warning
w0rp via Digitalmars-d
digitalmars-d at puremagic.com
Thu Apr 23 05:37:22 PDT 2015
On Wednesday, 22 April 2015 at 10:36:04 UTC, Jonathan M Davis
wrote:
> D arrays were designed in a way that they avoid segfaults;
> otherwise an
> empty array and a null array would not be considered equal, and
> doing stuff
> like trying to append to a null array would segfault. You have
> to work at it
> to get a segfault with D arrays. That doesn't mean that the
> optimizer does
> the best job (as evidenced by 14436), but D arrays are quite
> clearly
> designed in a manner that avoids segfaults and conflates null
> with empty as
> a result.
>
> - Jonathan M Davis
This is one of my favourite features of D. I've seen so many
problems in Java where someone passes null instead of an
ArrayList to a method and it throws a NullPointerException. I
love that I can just use foreach on a null slice, or check its
length, and not care if it's null most of the time. (But still
check if it's null if I really, really care.)
More information about the Digitalmars-d
mailing list