Deprecate `!a == b`

IchorDev zxinsworld at gmail.com
Wed Aug 14 13:26:44 UTC 2024


On Tuesday, 13 August 2024 at 21:13:17 UTC, Dennis wrote:
> On Tuesday, 13 August 2024 at 20:30:10 UTC, IchorDev wrote:
>> But I’ve also never seen anyone think this would work?
>
> It's easy to have a lapse of focus. Last hour, I accidentally 
> used `&&` for bit masking instead of `&`. I also sometimes 
> write `if (x = 3)` by mistake, or forget a `return` statement 
> like this:
>
> ```D
> bool f(int x)
> {
>     x == 3;
> }
> ```

Wow you have some… strange problems.

> Luckily the D compiler catches these. It's not that I thought 
> these things would work in D, but simple human error.

When you write the wrong thing, you get the wrong result. The 
language doesn’t pull any punches when it comes to much more 
complex things, so why be pedantic with something so elementary? 
If you want something like this to have an anti-goof mechanism, 
let’s just add such a mechanism for all of the other situations 
that might trip up a beginner:
- mutability attributes are transitive —> always require 
parenthesis after mutability attributes
- integral to floating point conversion can occur implicitly —> 
require a cast
- operator precedence is arbitrary —> require parenthesis around 
every operator
- cast doesn’t always do the same thing —> require a cast keyword 
after the type to make sure the programmer knows what type of 
cast it is (e.g. `cast(long, signExtend)myInt`)
- dereferencing `null` values —> require a cast to `typeof(null)` 
;)
- contracts shouldn’t have side effects —> treat contract code as 
`pure`
- integer promotion is stupid —> require a cast

> It's also worth noting that things are different in other 
> programming languages. In some languages the last expression is 
> automatically returned.

Other languages will always have things that work in 
contradictory ways, should we really shape the language around 
that?
Also if we added last-expression return then it would generally 
be convenient, instead of inconvenient like the proposed feature. 
Not that I’m particularly for or against last-expression return, 
it is what it Is.

> And in Python, the order of operations makes `!a == b` actually 
> work like most (new) programmers intend

Exceptions terminate for loops, numbers are immutable class 
instances, `+`, and now this too? This is no python, it’s more 
akin to Jörmungandr!


More information about the dip.ideas mailing list