float init 0 request

ABrightLight example at example.com
Fri Aug 14 08:19:51 UTC 2026


On Friday, 14 August 2026 at 06:38:02 UTC, Walter Bright wrote:
> Floats are default initialized to NaN so people will be coerced 
> to explicitly code what they want the initialized value to be.
>
> I've seen enough code where the programmer forgot to initialize 
> a float, it was defaulted to 0, and the wrong result was not 
> detected.
>
> ```d
> float f;     // code reviewer: did the programmer intend it to 
> be 0?
> float g = 0; // code reviewer: yes, the programmer likely meant 
> to initialize it to 0
> ```
>
> It's similar to pointers being default initialized to null. 
> Trying to use a null pointer will result in a seg fault.
>
> Most people decry this, but it's actually a great feature. If 
> there's a bug in the code, it's better to find it sooner rather 
> than after you ship.

Hi Walter, I really appreciate the response, however I think that 
all the points I wrote were unaddressed (I mentioned the 
comparison with null pointers and why it is my opinion that it is 
a false equivalence as well).

Nevertheless, the topic is relatively low importance to me and 
I'm okay with just using a linter to remind myself to explicitly 
initialize the floats. I just figured the change would be an easy 
QOL improvement for most users.

With regards to erroring if they're not initialized, that would 
be a very good alternative to 0 init as well (I mentioned that 
too).


More information about the Digitalmars-d mailing list