string <-> null/bool implicit conversion

deadalnix via Digitalmars-d digitalmars-d at puremagic.com
Fri Aug 21 17:04:32 PDT 2015


On Thursday, 20 August 2015 at 20:39:01 UTC, Timon Gehr wrote:
> 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.

Note that even if you put that asside, D makes the difference 
between equality and identity. null check is an identity check, 
while truthiness is a value check. The semantic is not coherent.


More information about the Digitalmars-d mailing list