Should you be able to initialize a float with a char?
Walter Bright
newshound2 at digitalmars.com
Thu May 19 18:32:59 UTC 2022
On 5/19/2022 12:57 AM, bauss wrote:
> 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.
D's rules added some constraints to C's rules to prevent loss of data with
implicit casting. I don't see how D's implicit casts are a dangerous source of bugs.
> 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.
It turns out that for performance reasons, you definitely want to treat UTF-8 as
individual code units. Autodecode taught us that the hard way.
> Upper-casing in unicode is not as simple as an addition, because the rules for
> doing so are language specific.
I'm painfully aware that the Unicode consortium made it impossible to do
"correct" Unicode without a megabyte library.
> Even with ASCII you can't just rely on a mathematic computation, because not all
> characters can change case, such as symbols.
Yes, you can. I posted the code in another post in this thread. ASCII hasn't
changed in my professional lifetime, and I seriously doubt it will change in yours.
> If D is to ever attract more users, then it must not surprise new users.
The only problem we've had with D chars is autodecoding, which ironically does
what you propose - treat everything as Unicode code points rather than code units.
It's a great idea, but it simply does not work, and it took us years to become
convinced of that.
More information about the Digitalmars-d
mailing list