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

bauss jj_1337 at live.dk
Thu May 19 07:57:54 UTC 2022


On Thursday, 19 May 2022 at 03:46:42 UTC, Walter Bright wrote:
>
> Casts are a common source of bugs, not correctness. This is 
> because it is forced override of the type system. If the types 
> change due to refactoring, the cast may no longer be correct, 
> but the programmer will have no way of knowing.

I'd argue that implicit casts are more so in some cases.

This is one of those cases.

And also you shouldn't really do arithmetic operations on chars 
anyway, at least not with unicode and D is supposed to be a 
unicode language.

Upper-casing in unicode is not as simple as an addition, because 
the rules for doing so are language specific.

Changing case in one language isn't always the same as in another 
language.

Even with ASCII you can't just rely on a mathematic computation, 
because not all characters can change case, such as symbols.

That's why string/char manipulation should __always__ be a 
library solution, not a user-code solution. The library should 
handle all these rules.

The user should absolutely not be able/have to to mess this up by 
accident, unless they really really want to.

Sure a char might be represented by an integer type, but so is 
every single data type you can ever think of since they all 
convert to bytes.

If D is to ever attract more users, then it must not surprise new 
users.


More information about the Digitalmars-d mailing list