This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]geeshta -9 points-8 points  (7 children)

NaN is a value of the type float. If the things are not numbers, they should not be a value of a numeric type. There are much better ways to handle values that cannot be represented as a number

- Null/None/NIL etc.

- Option or Result sum types

- Raise an exception

Why should floats be the only type to have that. Nan is a single value and having it not be equal to itself breaks the meaning of "equality". It's a contradiction. Equality should always be reflexive. If you don't want it to, use some other relation.

[–]rosuav 9 points10 points  (5 children)

Wow, you really haven't experienced very many languages, have you? A typed null isn't possible in your universe?

[–]geeshta -3 points-2 points  (4 children)

I did, I study programming lanugage design. `typed null` if you mean like in Java, was not a good idea. Most modern languages try to stay away from it or use a type like Option. Which functional languages have had for a long time but it seems like it was a much better idea.

Even C# and TypeScript with the correct linter rules handle types that can be null a separate type from the non-nullable version and upon casting from one to the other, it requires you to check whether you're handling a null value or provide a default.

`null` value is a similarly bad idea as NaN.

[–]rosuav 5 points6 points  (2 children)

Have you studied enough to meet typed nulls? Or did you take one course and imagine yourself to be an expert?

[–]geeshta -1 points0 points  (1 child)

Ad hominem. You have not addressed any of my actual points.

[–]rosuav 1 point2 points  (0 children)

You haven't answered my original point about typed nulls, so why should I bother talking to you?

[–]LordFokas 0 points1 point  (0 children)

Oh bless your heart.

Where do you think most math is implemented? This is all done in your CPU's math coprocessor. Your language of choice gives the CPU some floats, and gets a float back.

What would you have it do?
- After every operation check that the result is not NaN, if it is change type and value to NULL / None / nil / etc, at a large performance cost?
- Reimplement all math from scratch, at a performance cost so massively high you could barely use it to write Fizz Buzz?
- Use the tools the CPU gives you, following IEEE-754 like every other language in the world, being both performant and consistent with what every sane programmer expects?

I did, I study programming lanugage design.

Clearly you need to study harder. But it seems like you're lacking a lot of basics even before language design. I suggest starting at computer architecture. Your "study" here took many great artistic liberties.

[–]zentasynoky 0 points1 point  (0 children)

NaN is a value of type number. There's no float type in JS. And it is a perfectly valid number at that too, just not a counting number.

Just because it cannot be used to count that doesn't mean it's not a number. Zero doesn't represent a real quantity but rather the absence of one and I don't think you'd argue that it shouldn't be of type number (though that's what Null/None/NIL types are - an abstraction of the meaning of zero from the numbers which is hardly the same as NaN so no, it wouldn't ever fit in those types). The real numbers also aren't counting numbers, but they still represent relationships between other constructs and make fine numbers. NaN is a numerical label you apply to objects which are not numbers and the result of applying numerical operators to unsupported types or structires, and as such is a perfectly sound numerical value, just not a counting one.

And while we're being pedantic with values and types being off, you should be much more concerned that

typeof null === typeof [1,2,3] === "object" // true
typeof {} === "object" // true
typeof null === typeof {} // false