Should you be able to initialize a float with a char?

forkit forkit at gmail.com
Fri May 20 22:10:43 UTC 2022


On Friday, 20 May 2022 at 16:02:15 UTC, Steven Schveighoffer 
wrote:
>
> I actually am fine with, even *happy* with, implicit 
> conversions that D has, *except* the bool and char implicit 
> conversions *from* integers. I've used Swift where implicit 
> conversions are verboten, and it's non-stop pain.
>
>> It's clear to me that there is no set of rules that will 
>> please everyone and is objectively better than the others. At 
>> some point it ceases to be useful to continue to debate it, as 
>> no resolution will satisfy everyone.
>
> Of course. There's always a tradeoff. It comes down to, when 
> does the language surprise you with a weird thing (like an 
> overloaded function that takes bool accepting an int enum 
> because it can fit)? If the choice is between those surprises 
> and cast-inconvenience, what is worth more? There is no right 
> answer.
>
> -Steve

Actually, there is a right answer.

And that's to let the programmer know when this is occuring, if 
the programmer wants this information (and not requiring the 
programmer to go look at the assembly!!!).

Or, possibly, for the programmer to disable implicit casts, via 
some annotation -> @noImplicitCasting!

I do not like D being like C when it comes to the many unexpected 
things that can occur due to implicit type casting by the 
compiler.

D needs to be (much) better than C.



More information about the Digitalmars-d mailing list