Annoyance with new integer promotion deprecations

Adam D. Ruppe destructionator at gmail.com
Mon Feb 5 23:56:51 UTC 2018


On Monday, 5 February 2018 at 23:34:59 UTC, Steven Schveighoffer 
wrote:
> But for integer division and assignment to float, it's quite 
> obvious that it doesn't work with almost all combinations.

So let me take two steps there to get to my point:

1) Given:
     byte a, b;
     byte c = a + b;

The cast seems a bit silly: you are already explicitly using 
`byte` everywhere, so your intention is pretty clear: you only 
want to use the bytes and are ok with the rest of it being 
discarded. Therefore, I find the cast to be an unnecessary 
addition.

2) Change it to:
     byte a, b;
     int c = a + b;

This is directly analogous to the float example. Which, I agree, 
reasonable people can disagree on... but I'd be perfectly ok if 
the `a + b` was still typed `byte` just like above... and the 
data got discarded when assigned to the `int`.

Just like how you'd write cast(float) 1 / 2, here you can do 
cast(int) a + b to forcibly promote it.



And if we did this consistently across all things, it'd be pretty 
clear you should cast - 127 + 50 here would have discarded info 
so it would stand out a lot faster than just the -a edge case. So 
you'd learn it pretty quickly.


But I will grant it is going to be different than the C rules... 
so it would make copy/pasted code a pain. tho copy/pasted code is 
already a pain cuz you gotta insert casts to avoid the errors... 
but yeah an error is less of a hassle than silent change.

So I get why things are the way they are. I just still don't like 
it :P


More information about the Digitalmars-d mailing list