A Philosophy of Software Design
Kapendev
alexandroskapretsos at gmail.com
Sun Jun 28 19:00:34 UTC 2026
On Sunday, 28 June 2026 at 15:50:04 UTC, Forum User wrote:
> On Sunday, 28 June 2026 at 10:12:17 UTC, Kapendev wrote:
>> You can misuse any feature, even good ones like NaN.
>
> The question is: Does that feature support your work or does it
> complicate it?
>
>> It's a number type.
>
> NaNs are values, not types.
>
>> You usually want to continue executing instead of crashing
>> when doing math.
>
> That depends on what kind of program you have. If you write
> software for the navigation of military drones it is usually
> not necessary to also crash the program.
>
> If you write a program which influences political decision
> making you should favor crashing over giving poor advise.
>
>> "Garbage data" in this specific case is good and an OK way to
>> handle errors.
>
> Garbage data is a sign of a numerical error which is by
> definition not "good". And having garbage data lingering around
> for later programmatical examination is the very last thing you
> want.
>
>> If it was another kind of type,
>
> Uh, now it is not a type?
I'm saying that the NaN value makes sense for floats, a number
type. Not that NaN is a type.
Also, it's not the garbage that's good, but the signal it sends
that something is wrong in a specific code path.
NaN is not designed to handle everything. If you are dealing with
a problem that requires specific constraints and you have tested
that you actually need that, then wrapping a number type with a
struct is the solution. D makes that pretty easy too.
More information about the Digitalmars-d
mailing list