2 ms·
Doable in TypeScript[0], but I'd wager if that's really necessary. [0]: https://www.typescriptlang.org/play/?#code/C4TwDgpgBAogdgVwLYQE4ENgQDwDkoQAeWcAJgM5SJIB
by whilenot-dev 2y ago
Doable in TypeScript[0], but I'd wager if that's really necessary.
[0]: https://www.typescriptlang.org/play/?#code/C4TwDgpgBAogdgVwLYQE4ENgQDwDkoQAeWcAJgM5SJIBGaANFAIIDGLBxEZl1dqA2gF0oAXihCAfKOZt+AcgA2XAObAAFnOFESFKLgBQUKAH4ZLfrzSDDUAFyxqaTDlyN+AOk+sWjb-KVwqhqCghIA3Pr6oJBQAJJwwABK6IE4AGIcOjzIfIwAKplcupaoUmIwhCwKCKQ48MhOWNh5Eoz1KBhNaRLhkdHQBWLxSSnKOABMAAyMAIyTk+FAA https://www.typescriptlang.org/play/?#code/C4TwDgpgBAogdgVwL... from StackOverflow[1]
[1]: https://stackoverflow.com/questions/39494689/is-it-possible-to-restrict-number-to-a-certain-range https://stackoverflow.com/questions/39494689/is-it-possible-...
- josephg 2y ago> but I'd wager if that's really necessary. I think its more useful in a language like rust, because the compiler can use that information to better optimize the emitted assembly.
- whilenot-dev 2y agoEven in compiled languages I think the benefits won't outweigh the difficulties in compiler optimization. It starts with the question of how I would like to design my sequences: - Is it the range (0, 10] in steps of 1? - Is it the range (0, 2^10) in steps by the power of 2? - Is it the range (0.0, 2PI] in steps of EPSILON? How would the compiler engineer generalize this optimization? And the question would continue whether I'd be really able to define them that precisely before runtime. Most applications are just dealing with lightweight structures, mostly serialized JSON nowadays, and then even there are enough fuck-ups[0] where such an optimization wouldn't help at all. I can imagine the places where they really matter are some heavy memory intensive data structures like deep neural networks, graphics or video and the like - for the time being they're just dealing with tensors of data type floatX, and that seems to be fine AFAIK. I mean, I'd be really nice if the smaller memory footprint could come out-of-the-box during compilation. But all the CLI tools written in rust certainly don't have the use case to put this complication on the shoulders of compiler research. [0]: https://nee.lv/2021/02/28/How-I-cut-GTA-Online-loading-times-by-70/ https://nee.lv/2021/02/28/How-I-cut-GTA-Online-loading-times...