908 karma · joined September 20, 2012
And so it’s a bad idea because…?
The whole idea is to notice a bug before it ships. Asserts are usually enabled in test and debug builds. So having an assert hit the “unreachable” path should be a good way to notice “hey, you’ve achieved the unexpected” in a bad way. You’re going to need to clarify in more detail why you think that’s a bad thing. I’m guessing because you would prefer this to be a real runtime check in non debug builds?
That’s not quite true. Picking between two “buckets” still requires knowing how many “balls” are in each which is state. That state can be local to each server or global, that state can be accessed concurrently or synchronously, but you still have the same problem to solve.
Generally speaking, something where:
1. The data is in memory or can be made to be, for the duration of the need.
2. The overall throughput isn’t limited by some external I/O operation (eg: cache servers might seem like “memory hungry” things, but will bottleneck on network throughput before memory throughput [note: latency is definitely not throughput here]). - the CPU operations involved once data is fetched from memory are very cheap, but also generate a sequential but high volume of writes. Maybe an ideal example is incrementing every integer in a large array by 1 since reads and writes are predictable and SIMD instructions can push the theoretical per clock CPU throughput even higher.
Disclaimer: I might be missing some other scenarios from a lack of creativity. The question you asked got more interesting the longer I thought about it, and I think it might have something to do with why this “Memory Bandwidth Beast” hasn’t yet had its day in the sun.
Format strings, for example- are essentially compile time macros in rust in order to avoid all the fun kinds of string handling bugs that C’s implementation allowed- but that means no runtime customization without also defining were alternate formats live (and how they’re verified, etc). Not supporting multiple languages is a feature, not a bug. If you need multi language support, you need to a library to define those semantics in a way that fits or use case.
Maybe if you bake in assumptions about the deployed environment at compile time you can catch errors earlier for your specific environment, but all environments? No. That’s not the responsibility of the standard library and given the language lacks a single specific runtime target- definitely not the responsibility of the language/compiler. This is instead a classic use case for tests and opinionated (optional/third party) libraries instead.