As someone coming from Java to use D, I find it myself quite annoying that float and double are initialized to nan
.
This is really bad, it is hard to detect for newcomers, there is no flag by default to throw an exception when some operation on nan is done. It can be misleading if you're not paying a lot of attention to what you're doing.
What I suggest is what any sane people would: use 0 as the start for float and double. 0 is the most common sense as a starting point for everything, and, there are 2 options we could go:
1: Emit a compilation error that every variable must be initialized (I thought D were trying to avoid runtime errors)
2: 0 init all types, so, none is actually invalid before use
Even char
took me as surprise to know it actually starts as 0xff, I lost a bit of time trying to find that bug because it is so common that variables init as zero.
Although the char
is a bit different beast in terms of breaking change, I really can't see anyone actually depending that your float is being initialized with nan
, so I really would like to know how much people agree with this idea. It is so common to stumble on that problem that it is starting to feel as a real mistake.