dmd foreach loops throw exceptions on invalid UTF sequences, use replacementDchar instead

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Mon Nov 8 12:02:12 UTC 2021


On Monday, 8 November 2021 at 08:18:51 UTC, FeepingCreature wrote:
> (Actually, an exception in cast(string) would be the best.)

D should distinguish more clearly between strong and weak casting 
at the language level. UTF-8 is now so dominating that D really 
should reconsider the string type and make it so it is required 
to be valid UTF-8 (like Python3 did). C++ has even introduced a 
new character type to signify UTF-8, I use it all the time.

> And that's why I think ReplacementChar/NaN are no better than 
> 0.0. You either embrace them fully as "valid" data, or you 
> handle them at the site of origin; any compromise just makes 
> you worse off than either extreme.

It is very difficult to follow your line of reasoning, because 
ReplacementChar is nothing like qNaN, it is more like sNaN. 
ReplacementChar is not the result of an approximation failure, it 
is corruption of the input (or maybe a foreign encoding).

Getting a 0.0 instead of qNaN in a signal is absolutely 
disastrous. Walter is 100% right on that one. 0.0 will introduce 
a peak across the frequency range. qNan can be removed with no 
distortion.

Should you express your types strongly? Yes, but then you also 
should include things like negative numbers, denormal numbers, 
±infity, ranges [1.0-0.0] and so on.



More information about the Digitalmars-d mailing list