August 20, 2015
On Thursday, 20 August 2015 at 19:54:22 UTC, Steven Schveighoffer wrote:
> On 8/20/15 3:41 PM, Jonathan M Davis wrote:
>> On Thursday, 20 August 2015 at 17:50:11 UTC, Steven Schveighoffer wrote:
>>> if(arr != null)
>>
>> Definitely don't do that. IMHO, "== null and "!= null" should be
>> illegal. If you really want to check for null, then you need to use "is
>> null" or "!is null", whereas if you want to check that an array is
>> empty, check its length or call empty. By using "== null" or "!= null",
>> you tend to give the false impression that you're checking whether the
>> object or array is null - which is not what you're actually doing.
>
> On the contrary, checking if it's equal to null checks to see if it has the same elements as null. That's exactly what I would want.

And why would you want that? The length is meaningless if the pointer is null. It shouldn't even be possible for the length to be anything other than zero if the pointer is null.

- Jonathan M Davis


August 20, 2015
On 08/20/2015 10:26 PM, David Nadlinger wrote:
> On Thursday, 20 August 2015 at 16:45:18 UTC, Márcio Martins wrote:
>> Having 2 empty strings evaluate differently is very unintuitive and
>> error-prone, in my opinion.
>
> It's even worse: http://dpaste.dzfl.pl/ba3376feca8e
>
> The arrays are equal, but their Boolean value is not.
>
> I don't get how Andrei can reconcile this with his "D avoids unforced
> errors" stance.
>
>   — David

By denying that it is an error and by playing down its significance, IIRC.
Same about [] is null, [1][1..1] is null, but {auto a=[1]; return a[1..1];}() !is null and related cases.
August 20, 2015
On 08/20/2015 10:38 PM, Jonathan M Davis wrote:
> On Thursday, 20 August 2015 at 19:54:22 UTC, Steven Schveighoffer wrote:
>> On 8/20/15 3:41 PM, Jonathan M Davis wrote:
>>> On Thursday, 20 August 2015 at 17:50:11 UTC, Steven Schveighoffer wrote:
>>>> if(arr != null)
>>>
>>> Definitely don't do that. IMHO, "== null and "!= null" should be
>>> illegal. If you really want to check for null, then you need to use "is
>>> null" or "!is null", whereas if you want to check that an array is
>>> empty, check its length or call empty. By using "== null" or "!= null",
>>> you tend to give the false impression that you're checking whether the
>>> object or array is null - which is not what you're actually doing.
>>
>> On the contrary, checking if it's equal to null checks to see if it
>> has the same elements as null. That's exactly what I would want.
>
> And why would you want that?

Because his goal is to check whether the array is empty or not, and comparing to null is one effective way to do it.

> The length is meaningless if the pointer is
> null. It shouldn't even be possible for the length to be anything other
> than zero if the pointer is null.
>
> - Jonathan M Davis
>
>

August 20, 2015
On 8/20/15 4:38 PM, Jonathan M Davis wrote:
> On Thursday, 20 August 2015 at 19:54:22 UTC, Steven Schveighoffer wrote:
>> On 8/20/15 3:41 PM, Jonathan M Davis wrote:
>>> On Thursday, 20 August 2015 at 17:50:11 UTC, Steven Schveighoffer wrote:
>>>> if(arr != null)
>>>
>>> Definitely don't do that. IMHO, "== null and "!= null" should be
>>> illegal. If you really want to check for null, then you need to use "is
>>> null" or "!is null", whereas if you want to check that an array is
>>> empty, check its length or call empty. By using "== null" or "!= null",
>>> you tend to give the false impression that you're checking whether the
>>> object or array is null - which is not what you're actually doing.
>>
>> On the contrary, checking if it's equal to null checks to see if it
>> has the same elements as null. That's exactly what I would want.
>
> And why would you want that? The length is meaningless if the pointer is
> null. It shouldn't even be possible for the length to be anything other
> than zero if the pointer is null.

This makes me think you misunderstand what I am doing.

-Steve
August 20, 2015
On 08/20/2015 10:43 PM, Steven Schveighoffer wrote:
> On 8/20/15 4:38 PM, Jonathan M Davis wrote:
>> On Thursday, 20 August 2015 at 19:54:22 UTC, Steven Schveighoffer wrote:
>>> On 8/20/15 3:41 PM, Jonathan M Davis wrote:
>>>> On Thursday, 20 August 2015 at 17:50:11 UTC, Steven Schveighoffer
>>>> wrote:
>>>>> if(arr != null)
>>>>
>>>> Definitely don't do that. IMHO, "== null and "!= null" should be
>>>> illegal. If you really want to check for null, then you need to use "is
>>>> null" or "!is null", whereas if you want to check that an array is
>>>> empty, check its length or call empty. By using "== null" or "!= null",
>>>> you tend to give the false impression that you're checking whether the
>>>> object or array is null - which is not what you're actually doing.
>>>
>>> On the contrary, checking if it's equal to null checks to see if it
>>> has the same elements as null. That's exactly what I would want.
>>
>> And why would you want that? The length is meaningless if the pointer is
>> null. It shouldn't even be possible for the length to be anything other
>> than zero if the pointer is null.
>
> This makes me think you misunderstand what I am doing.
>
> -Steve

Which was my original point. :o)
August 20, 2015
On 8/20/15 4:45 PM, Timon Gehr wrote:
> On 08/20/2015 10:43 PM, Steven Schveighoffer wrote:
>> On 8/20/15 4:38 PM, Jonathan M Davis wrote:
>>> And why would you want that? The length is meaningless if the pointer is
>>> null. It shouldn't even be possible for the length to be anything other
>>> than zero if the pointer is null.
>>
>> This makes me think you misunderstand what I am doing.
>>
>
> Which was my original point. :o)

touche ;)

-Steve
August 21, 2015
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?

- Jonathan M Davis
August 21, 2015
On Thursday, 20 August 2015 at 20:26:09 UTC, David Nadlinger wrote:
> It's even worse: http://dpaste.dzfl.pl/ba3376feca8e
>
> The arrays are equal, but their Boolean value is not.
>
> I don't get how Andrei can reconcile this with his "D avoids unforced errors" stance.

The only technical excuse for the bug is code breakage, which can be mostly addressed by dfix, but that's yet another problem: tools like dfix are shunned for some reason.
August 21, 2015
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
August 21, 2015
On 08/21/2015 12:50 PM, Steven Schveighoffer wrote:
> So checking whether the array is null (i.e. empty) *is* what I'm doing,

Nah, you're checking whether it /equals/ null. :-)