Advertisement
Advertisement
β‘ Community Insights
Discussion Sentiment
40% Positive
Analyzed from 515 words in the discussion.
Trending Topics
#nan#code#nans#point#initialized#floating#programming#default#wrong#don
Discussion Sentiment
Analyzed from 515 words in the discussion.
Trending Topics
Discussion (16 Comments)Read Original on HackerNews
I don't know of any other programming language with this safety feature.
Also, the D `char` type is initialized to 0xFF, not 0, because Unicode says that 0xFF is an invalid character.
The trouble with it is a bug I've seen often. People will get an error message about an "uninitialized variable". Then they go into "just get the compiler to shut up" mode, amd pick "0" as the initializer. Then, the program compiles and runs, and silently produces the wrong answer. Code reviews will simply pass over the "0" initializer, as it looks right.
With default NaN initialization, the programmer is more likely to stop and think about it, not just insert 0.
Another issue with it is:
For the purposes of code clarity I don't want to see a variable initialized to a value that is never used, just to shut the compiler up.Not so. You may be thinking of UTF-8 encoding. 0xff is DEL in Unicode.
For me, the major advantage of nan boxing is that you don't have to allocate a whole class of types (like floats). That saves so much at garbage collection time.
------------
[1] https://en.wikipedia.org/wiki/Hilbert%27s_paradox_of_the_Gra...