[OT] The Usual Arithmetic Confusions

Walter Bright newshound2 at digitalmars.com
Sat Feb 5 08:47:52 UTC 2022


On 2/4/2022 7:48 PM, Adam D Ruppe wrote:
> On Saturday, 5 February 2022 at 02:43:27 UTC, Walter Bright wrote:
>> We considered that and chose not to go that route, on the grounds that we were 
>> trying to minimize invisible truncation.
> 
> I know how D works. I know why it works that way. Hell, I implemented part of 
> the VRP code in dmd myself and have explained it to who knows how many new users 
> over the last 15 years.
> 
> What I'm telling you is *it doesn't actually work*.
> 
> These forced explicit casts rarely prevent real bugs and in exchange, they make 
> the language significantly harder to use and create their own problems down the 
> line.
> 
> Loosening the rules would reduce the burden of the many, many, many false 
> positives forcing harmful casts while keeping the spirit of the rule. It isn't 
> just *invisible* truncation you want to minimize - it is *buggy* invisible 
> truncation.
> 
> You want the compiler (and the casts) to call out potentially buggy areas so 
> when it cries wolf, you actually look for a wolf that's probably there.

I use D all day every day, the time, and I don't seem to be having these 
problems. I did a:

     grep -w cast *.d

across src/dmd/*.d, and found hardly any casts to short/ushort that would fall 
under the forced cast category you mentioned. Granted, maybe your style of 
coding is different.

Doing the same grep across phobos/std/*.d, rather little of it which I have 
written, I found zero instances of forced cast to short/ushort.

As for "rarely", these kinds of bugs are indeed rare, but can be invisible yet 
significant. It's just the sort of thing we want to catch.


More information about the Digitalmars-d mailing list