On Thu, Jun 7, 2012 at 6:50 PM, Minas <minas_mina1...@hotmail.co.uk> wrote:
> I agree that the default value for floats/doubles should be zero. It feels > much more natural. > The point is to make sure code is correct. Initializing your variables should be what feels natural. Leaving then uninitialized is bad style, bad practice, and generally a bad idea. If getting stung by a float initializing to NaN is what it takes to make that happen, so be it. > > 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: Actually, as far as I know, floats have been initialized to NaN since D first appeared in 2001. This isn't news. > > int sum; > > for(...) > sum += blah blah blah > > And it works. > In any other systems language, this would be undefined behavior. D is simply trying to make initialization bugs as obvious as possible. With ints, the best we can do is 0. With floats, NaN makes it better.