DMD 0.148 release

Oskar Linde oskar.lindeREM at OVEgmail.com
Tue Feb 28 02:30:27 PST 2006


Kyle Furlong skrev:
> Oskar Linde wrote:
>>
>> if (a !is null || b !is null)
>>
>> instead of:
>>
>> if (a || b)
>>
> 
> I would say that the second construct is much less reliable, 
> maintainable, and safe than the first. Therefore, the type system should 
> disallow the second with a pure boolean type.

I have seen bugs introduced by changing

if(!a || !b)

into

if(a !is null || b !is null)

And the double negation nature of !is null makes this quite hard to spot 
(for both me and the one introducing the bug). This contradicts your 
saying that it makes the code "much more reliable, maintainable and 
safe". Consider the sentences:

"If a or b"

compared to:

"If a is not nothing or b is not nothing"

Which one is easier to grasp and get right?

(!is also takes an extra step when it is parsed by the reader as "not 
is" and then (in most western languages at least) has to be transformed 
into "is not")

What do you base your statements on? Do you have examples of where 
(a||b) is less reliable or less safe? Why would it be less maintainable? 
It is clearer (less complex) an has a well defined semantic meaning.

JMHO

/Oskar



More information about the Digitalmars-d-announce mailing list