The more interesting question
Jonathan M Davis
jmdavisProg at gmx.com
Wed May 16 16:04:52 PDT 2012
On Wednesday, May 16, 2012 19:52:07 Alex Rønne Petersen wrote:
> I guess we can conclude that one should not use 'null' or 'is' for
> arrays unless absolutely necessary. '[]' and '==' should probably do for
> the majority of code.
The only reason to use is is if you're checking for identity rather than
equality. == checks for equality. It should be clear when you need one or the
other.
null and [] are essentially equivalent, so it doesn't really matter which you
use.
However, I'd argue that using == with null or [] is a bad move, because it
tends to show a lack of understanding, simply because it's so natural for
people to try and check whether something is null by comparing against ==, and
that _doesn't work_. So, if you want to check whether an array is empty, use
empty or length == 0, whereas if you want to check whether an array is null,
then use is null.
But aside from the issues of clarity surrounding checking whether an array is
empty by using == null or == [], I think that it's quite clear when == or is
should be used. If it's not, it's because you don't understand the differences
between the two.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list