Movement against float.init being nan

claptrap clap at trap.com
Sun Aug 21 16:01:21 UTC 2022


On Sunday, 21 August 2022 at 15:26:54 UTC, Walter Bright wrote:
> On 8/21/2022 2:01 AM, claptrap wrote:
>> So from my experience the rational is based on two fallacies.
>> 
>> 1. That using zero as default init would hide the bug.
>
> If the computed answer is 1.7239 rather than 1.7230 because of 
> an erroneous 0 input, how would you know it is wrong? But if 
> the computed answer is NaN, you *know* it is wrong.

Go through all the math functions in phobos and see what would 
happen if you zeroed out some random local variables, you wont 
get results that are a tiny fraction of a percent out, it'll be 
way off 99 times out of 100.

Im not saying it cant happen, but that it's vastly exaggerated 
how likely it is that an erroneous zero init wont be obvious.


>> 2. That people will just stick zero in because they don't know 
>> what it should be.
>
> I know *you* wouldn't do it (I wouldn't either), but like I 
> wrote, I've seen it happen. I've also seen cases of:
>
>     double x = 0;
>     ... no uses of x ...
>     x = 5;
>     ...
>
> where the initialization was put in to shut the compiler up. 
> But to one unfortunate enough to be reviewing unfamiliar code, 
> this double initialization has a smell about it - which 
> initialization is the correct one? Why was it initialized to 0 
> when that makes no sense for the algorithm?

Id still rather have the compiler error, that is more helpful to 
me that preventing somebody else writing crappy but *working* 
code.




More information about the Digitalmars-d mailing list