Deprecate `!a == b`

IchorDev zxinsworld at gmail.com
Wed Aug 14 15:04:13 UTC 2024


On Wednesday, 14 August 2024 at 14:36:50 UTC, Dennis wrote:
> On Wednesday, 14 August 2024 at 13:26:44 UTC, IchorDev wrote:
>> Wow you have some… strange problems.
>
> If you've never made such silly programming mistakes, enjoy it 
> while it lasts!

Thanks. I’m surprised my knackered brain still manages not to 
make such mistakes if they’re so common.

>> let’s just add such a mechanism for all of the other 
>> situations that might trip up a beginner:
>
> Interesting list. Some of them have been seriously suggested 
> for D or implemented in other languages. Specifically, D's 
> integer promotion rules get criticized a lot, and some 
> languages are a lot stricter about it.

Yes and I’m sure people have suggested requiring parenthesis 
after mutability attributes. The only one of those things I 
seriously want is requiring an explicit cast before dereferencing 
`null`; but it would require the compiler to literally be magical 
since it needs to be a compile-time feature obviously, but it 
depends on a runtime value.

> I do agree with you generally: just because a combination of 
> features is commonly used mistakenly, doesn't mean a special 
> case should be added disallowing the combination.
>
> However, there are cases where the ratio of erroneous usage / 
> intentional usage is so large, that a compiler error will in 
> practice reduce the total amount of 'programmer rage' so to 
> speak.

I feel like integer promotion is a much more pressing issue in 
that department. It’s one of the few things I wish we’d just bin 
because it’s so atrocious. And personally I’ve been screwed over 
by arithmetic operator precedence on many occasions.

> You apparently have seen intentional use [of `!a == b`], so it 
> makes sense you judge it as not worth adding an error for. I'm 
> actually curious, can you link to real code using that pattern 
> intentionally?

I don’t think I said that? I might’ve written something like that 
a long time ago in another language. I don’t usually read other 
people’s code for fun, but it’s the kind of thing I can see 
myself writing, although probably as `x == !y` because it looks 
nicer. Also C code often uses `int` for booleans, so code that 
interfaces with C could trigger this mechanism even if we add an 
exception for `bool`.


More information about the dip.ideas mailing list