floats default to NaN... why?

F i L witte2008 at gmail.com
Sat Apr 14 08:10:02 PDT 2012


On Saturday, 14 April 2012 at 12:48:01 UTC, Andrej Mitrovic wrote:
> On 4/14/12, bearophile <bearophileHUGS at lycos.com> wrote:
>> Having a variable not initialized is a common source of bugs.
>
> I'm going to argue that this was true for C/C++ but is much 
> less true
> for D. One benefit of having integrals initialized to 0 is that 
> you
> now have a defined default that you can rely on (just as you 
> can rely
> on pointers being null by default). Personally I find this to 
> be a big
> win in productivity. If the language/runtime does something 
> defined
> for me then I can focus on more important things.

Amen! This is exactly what I'm trying to get at. The compiler 
provides defaults as a convince feature (mostly) so that there's 
no garbage and so values are reliable. It's incredibly 
inconvenient at that point to have to remember to always 
explicitly init one specific type..

This feels very natural in C#.


More information about the Digitalmars-d-learn mailing list