float init 0 request
Walter Bright
newshound2 at digitalmars.com
Sat Aug 15 06:11:23 UTC 2026
On 8/14/2026 2:25 PM, Steven Schveighoffer wrote:
> In all the years I have used D, whenever I have forgotten to initialize a
> floating point number, the fix was ALWAYS to initialize explicitly to 0, because
> that's what I expected and desired to happen.
Yes, initializing to 0.0 is very common. And that works fine until the correct
initialization is 0.001, and there's an unrecognized bug in the output.
> This is a big stain on D, and it disrupts everyone's work unnecessarily. The
> problem is the distance from the error to the result.
The problem with default initialization to 0.0 is not recognizing that the
result is in error, which I submit is much much worse. It costs orders of
magnitude less money to fix a bug made very visible with a NaN output than
output that is just slightly wrong and unnoticed out in the field.
When reviewing code, and you see:
```d
float f;
```
is the intention to initialize it to zero, or did the programmer simply forget
to initialize it? I've had more than enough of the latter in actual code.
P.S. In case it isn't obvious, this derives from my experience designing flight
controls for the 757. You really really really want to find all the bugs before
cutting metal or, heaven forbid, trying to lift it off the runway. Inconvenience
be damned.
More information about the Digitalmars-d
mailing list