this post was submitted on 29 Jul 2024
115 points (97.5% liked)
Programming
17424 readers
27 users here now
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Rules
- Follow the programming.dev instance rules
- Keep content related to programming in some way
- If you're posting long videos try to add in some form of tldr for those who don't want to watch videos
Wormhole
Follow the wormhole through a path of communities [email protected]
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
You seem to be confused about what JS is. It's a high-level interpreted language. It's not C. Of course it can't open files. Can you imagine if any webpage could open files on your PC? This is like asking why Rust doesn't have a certain Blender shader node or Scratch block. The language fundamentally doesn't include those concepts directly. As an interpreted language, of course JS is going to access OS APIs through its host program. If the concern is that the APIs aren't standardized-- well, yeah, that's true. Although the basic stuff (file I/O) is included in runtimes directly.
Is there something I'm missing here? Why would you expect to be able to do bitwise operations on floats and get a sensible value? And if you want to do integer bitwise operations... you still can? Just use integer values and the bitwise operators? If you're complaining that you can't be sure if a number is an integer, that's 1. a separate issue, bitwise operations still work fine, and 2. easily solved.
Have you looked at the bit arrays JS has now?
Do you require multithreading for a language to be considered "good enough"? Why complain now that JS does have these abilities?
This is patently false. JS has sets, maps (actual ones, not objects like you were referring to), etc. We're soon getting records and tuples. If you want to build a linked list in JS, you do it the exact same way as you would in any other language. Not that it would be very useful.
No that's my point. You can't, because there's no such thing as an integer value. It's all floats, always. They get casted to integers, the binary operation is done, then they get converted back to floats. That's a lossy process, so some binary operations with certain values are simply not possible and you get weird results. The max width of an integer you can store is 53 bits, the maximum addressable width is 32 bits for binary operations. That's wonky.
Ah yes I forgot sets. But I don't think there's anything else? Last time I checked there were no binary trees, no proper (ring buffer) queues, no ordered sets, but I may be wrong on that. It's not enough imo for a proper standard library.
For everything else:
My point is that JS is an okay scripting language for the web. As I said, for that it's perfectly fine, though the frameworks are often lacking imo. But there is this tendency to use it to create backends, desktop applications and tooling. That's where the language falls apart, because it's not made for that. It needs to be more robust, well defined and fully featured to be used in those contexts, both in terms of JS itself, and its standard library. Same with TS.
I know and that's the point. It's underspecified for things outside the web, so it's terrible for those use-cases. You can make it work for Node, but not for Bun or any other runtime. And even then, the experience is acceptable at best.
I personally would never use it for such use-cases, but people keep touting it and TS as these amazing general purpose languages you can do anything in. You can, but you really shouldn't.
But you can. Any number that precisely represents a 32-bit integer can be used with binary operations as if it was one, and there will be no loss of information or unexpected results. Is it weird that JS has no integer type, or that its max safe integer representation caps out at 2^53? Yes, but that's not the complaint you made. Binary operations work literally perfectly as expected for any inputs that have the appropriate type. Actual float values are truncated, which fits the language design.
I'm sure you're aware of push, pop, shift, and unshift, which together can make a FIFO or FILO structure, or a more complicated one, from an array. If you're using TS you could create a semantic type that only allows a subset of these operations. I will concede that we have no tree type, although I'm not sure if that's standard in other languages? I haven't needed to use one myself.
Anyways, I won't fight you on JS being overused. I will say that it's flexible enough that it can be used in any way, even if it's not the greatest idea. Something like embedded programming or safety-related things shouldn't use JS. And as you keep mentioning, it wasn't made for low-level stuff, although it can do it. I don't think that's a requirement for a stdlib though.