Deprecate `!a == b`

Lance Bachmeier no at spam.net
Tue Aug 13 21:35:29 UTC 2024


On Tuesday, 13 August 2024 at 20:30:10 UTC, IchorDev wrote:

> Doesn’t require a DIP, but I’ve also never seen anyone think 
> this would work? Do we really need to pander to people who 
> don’t even understand that logical operators only *return* 
> `bool`? Maybe that seems harsh, but I have never even thought 
> of doing this because it’s just so obviously wrong—if I wrote 
> it then I must have meant what I wrote, and I was probably 
> happy with how it looked too. Having to wrap it in parenthesis 
> would just negate that and add to my code’s parenthesis hell.
>
> P.S. this isn’t a bug; and `!` is ‘logical not’, not ‘negation’.

It would make sense to allow it for only bools. However, we can 
write this code:

```
import std;

void main() {
     int z = 4;
     writeln(z == 2);
     writeln(!z == 2);
     writeln(!z == 0);
     writeln(z == 0);
}
```

The output is

```
false
false
true
false
```

It's hard to justify allowing something like that to slip through 
given that it's an easy mistake to make. A test might not even 
catch it.



More information about the dip.ideas mailing list