On Jun 7, 2012 9:53 PM, "Minas" <minas_mina1990@hotmail.co.uk> wrote:
>
> I agree that the default value for floats/doubles should be zero. It feels much more natural.
>
> I think the problem here is that people are thinking about some stuff too much. D is a rather new language that wants to be practical. Floats defaulting to NaN is NOT practical FOR MOST PEOPLE when at the same time I write:
>
> int sum;
>
> for(...)
>  sum += blah blah blah
>
> And it works.
>
> Having floats deaulting to a value that's un-natural for most people is, in my opinion, craziness. Even if that's "more" correct in a mathematical sense.
>
> Please excuse my English.

The idea isn't being "practical" exactly.  The idea was to use invalid values as defaults. Unfortunately things like ints don't have invalid values, so they chose zero.  The idea is to make people initialize their variables.  It would have been better to pick 19472937 as the int default because not many people will use that value.

The code you showed would be considered **bad** because you did not initialize your variables, however ints defaulting to zero is well defined so it isn't really a big deal.

With floats there is this wonderful value that ensures that nothing reasonable comes out of a bad calculation, NaN.  Therefore this is used as a default because if you forget to initialize your vars it will jump out at you.

This is the thought that was used and many people don't agree.  It is **very** unlikely to be changed now but __maybe__ D3 however far off that is.  I hope not though, I hope ints default to 8472927 instead, but everyone has different opinions.