On 8/20/15 11:15 PM, Jonathan M Davis wrote:
On Thursday, 20 August 2015 at 20:43:39 UTC, Steven Schveighoffer wrote:
This makes me think you misunderstand what I am doing.
If you care about whether an array is empty, you check whether its
length is 0 or you call empty (which checks whether the length is 0). If
you care about whether the array is null, you use "is null". I don't
understand what else you could possibly be doing. "!= null" is just
going to end up being equivalent to checking whether the length is 0,
because the elements won't be compared if the length is 0, but it gives
the false impression that you're checking whether the array is null -
hence why checking != null is a bad idea. What am I missing here?
You're missing that null is not a pointer in this context, it's an empty
array. So checking whether the array is null (i.e. empty) *is* what I'm
doing, and it makes perfect sense to me. The false impression is not one
of my doing. I can't help your C-based prejudices ;)
Timon is probably right that comparing the array to [] is less confusing
to others.
-Steve