float init 0 request

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Fri Aug 14 17:28:15 UTC 2026


On 15/08/2026 5:26 AM, Walter Bright wrote:
> On 8/14/2026 12:05 AM, Alexandru Ermicioi wrote:
>> Why not make it an error, a float that is not explicitly initialized? 
>> Would be way better than implicit nan initialization, right?
> 
> Because then you wind up with:
> 
> ```d
> float f = 0; // shut up the spurious compiler error message
> ...
> initialize(&f); // the actual initialization
> ```
> The 0 initialization is inserted to shut up the compiler, and it will 
> take the reviewer a bit of time wondering why f was initialized to the 
> wrong value.
> 
> In other words, redundant/vacuous assignments are a code smell.
> 
> It's a small point, but D is an elegant language, and requiring people 
> to write smelly code is not elegant.

Alternatively make the parameter out:

```d
void initialize(out float v);

float f;

initialize(f);
```



More information about the Digitalmars-d mailing list