Movement against float.init being nan
Dukc
ajieskola at gmail.com
Sat Aug 20 22:17:38 UTC 2022
On Friday, 19 August 2022 at 13:42:58 UTC, Hipreme wrote:
> 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.
I personally like how D does it. Once you know that floats have a
"nothing" value, it's very convenient that it's the
initialisation value, for the same reason `null` is a convenient
initialisation value for pointers and class references. But I can
see that if I didn't know about NaNs, this would be annoying. The
big weakness is that it goes against what C, C++ and C# (and
probably many other languages) do so one is easily surprised.
However, the big philosophy behind it is that D *always* uses an
"empty" value as the initialisation value if there is one, so for
D this is the right thing to do. Using 0 as float `.init` would
be inconsistent with rest of the language. Whether this
underlying philosophy is a good idea is debatable though.
Personally I think the philosophy has it's ups and downs but easy
to like once you get used to it.
More information about the Digitalmars-d
mailing list