What do you mean by all numbers being big endian? One thing I can think of is binary data reading APIs and I think these default to big endian because it's the standard network endianness
DataView.getUint32 and such use big endian by default which is complete bogus when you consider that there is practically no hardware that still uses big endian
In which case yeah, I wouldn't be surprised if this was a case of network protocols being big endian (stuff like TCP/IP packets) and JS following that lol. Fun fact, typed arrays (Uint32Array et al) use the system's native endianness instead of defaulting to anything
well i mean, it doesn't really matter what endianness is used by typed arrays as you're never gonna read their internal buffer, that said tho, i am happy to see that those that designed typed arrays didn't make a terrible and illogical design choice
as for the network endianness thing, it's still complete bs to have anything at all ever be big endian nowadays since pretty much all hardware computes in little endian and as such needs to waste at minimum 1 CPU cycle swapping the bytes
which raises the question of how tf we got here LMAO
how is it possible that a language used to perform operations on what is literally a machine with the sole purpose of doing math, can't do math properly LMFAO
Eh... I'd argue that your example is less surprising than OP's, which isn't really that bad itself.
Your example is "is 'new empty array' equal to 'other new empty array'?", and since most other languages default to reference equality for reference types, like arrays, IMO it'd be slightly more surprising for that to actually be true.
For OP's example, "no implicit conversion between different numeric types" is honestly a feature I kinda wish more languages had. The only one I can think of that does is rust. I do have to admit, though, that it's a bit surprising in the context of all the implicit conversion JS already does do.
since most other languages default to reference equality for reference types
It is a surprising behaviour, regardless of how many languages do it. Any empty array is semantically the same thing as any other empty array.
Having == perform a pointer comparison only really makes sense when the types you're dealing with are raw pointers (since there is no better notion of equality for raw pointers). For other types, it is a confusing and unexpected behaviour - if you write ==, you almost certainly want to check for semantic equality.
I guess it depends on how your intuition is calibrated. My first language was Java, which doesn't allow operator overloading, so == can only be reference equality.
this isn't about implicit conversion, it's about the fact that javascripts default number type isn't a 64-bit integer.
And yes, i do have the same complaint about C and C++ but at least you can argue about memory efficiency of using a 32-bit integer when it comes to those 2.
I think the problem with C is that it was originally designed for machines that aren't relevant anymore.
Back in the days of C being invented, memory was word-addressed. Integers smaller than a word had to be implemented by bit manipulation. C was very much defined so that int could be a word, so programs using int got good performance.
On modern architectures, there isn't really a single defined "word size", pretty much all the integer sizes up to 64-bit are the same performance, with the main performance differences between integers being memory reads/writes and how many you can fit in a packed SIMD register. So compiler authors just map char, short, int, long, and long long in a way that gives access to all the different supported sizes.
If you look at modern systems languages (Rust, Zig, etc), you'll notice that they use integer names like u32 or i64. In fact, the stdint.h header (added in C99 and C++11) defines fixed-width integers in C and C++ (e.g, uint32_t, int64_t, etc), and some coding standards for C and C++ mandate the use of fixed-width integers.
well, floats just get real messy real fast the moment you need to do any bitwise operations, also, every non-javascript based language has an integer for a default number type, why cant js just be normal
If only they had gone with Scheme instead of inventing JavaScript. ::sigh::
That said, modern JavaScript is a shockingly capable language, once you learn to deal with its warts. Yes, I'll still reach for something else if I'm not doing web development, but I don't hate it the way I used to.
17
u/definitelynotagirl99 Jul 16 '24 edited Jul 16 '24
I just discovered that, aparently, javascript interprets all numbers as big endian...
WHY?????????????????
edit:
It gets worse
all javascript numbers are floats?????????????????????
31
u/MinosAristos Jul 16 '24
JS and math are things that go together only out of necessity
8
u/k819799amvrhtcom Jul 16 '24
Javascript has bigint?! 😳
3
u/TamsynUlthara Jul 17 '24
If only they had gone with Scheme instead of inventing JavaScript. ::sigh::
That said, modern JavaScript is a shockingly capable language, once you learn to deal with its warts. Yes, I'll still reach for something else if I'm not doing web development, but I don't hate it the way I used to.
1
u/[deleted] Jul 23 '24
I want a language where I can add a bigint to a number and get the resultant address without fancy indexing pointer arithmetic.