Hacker News new | ask | show | jobs
by TheOtherHobbes 8 days ago
C syntax was never that great. It's basically mnemonic PDP-11 assembler with a few added data structures.

js is mutant C with dementia - hacked together over over a fortnight, full of inconsistencies and weird corners.

    console.log(1 + "2"); // "12"
    console.log(1 - "2"); // -1
    console.log(NaN === NaN); // false
    console.log(+0 === -0); // true

    const obj = {};
    console.log(obj.foo); // undefined, not an error
3 comments

NaN is a standardized dynamic languages datatype governed by IEEE 754, this is not something to complain about as its behavior is part of the official standard and for good reason, as outlined in the standard.
Why dynamic? `NAN != NAN` is just as true in C.
well as I understood it, it was implemented for languages without static data typing although I suppose you could implement it in other languages.

Also I suppose my memory could be pretty foggy as I don't think I've looked at the spec since about 2014.

To my understanding, NaN is a range of particular values (all exponent bits set to 1, mantissa nonzero) of the IEEE 754 float datatype, and its semantics are defined in the standard, including the "not equal to itself" semantic. If your language uses IEEE 754 floats and it has div or sqrt operations that don't raise exceptions on out of range inputs (which is something scientific computing people want very much, so it probably has them), then it must ensure nan != nan.
None of those examples are showing something you find wrong with the syntax
C syntax dropped the ball badly on operator precedence. Left Shift <<, Right Shift >>, and Bitwise And & should have been at the same priority as multiplication or division, while Bitwise Or (|) should have been at the same priority as addition.