this post was submitted on 29 Jul 2024
114 points (97.5% liked)

Programming

17378 readers
361 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 !webdev@programming.dev



founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] shy_mia@lemmy.blahaj.zone 1 points 3 months ago* (last edited 3 months ago) (1 children)

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?

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.

This is patently false. JS has sets, maps, etc...

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.

You seem to be confused about what JS is. It's a high-level interpreted language. It's not C.

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.

[–] Feathercrown@lemmy.world 4 points 3 months ago

You can’t, because there’s no such thing as an integer value. It’s all floats, always.

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.

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 queues, no ordered sets, but I may be wrong on that. It’s not enough imo for a proper standard library.

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.