4 ms·
One case where this is useful is where you want determinism. You don't need a particular order, but you do need it to be consistent. This comes up a lot in com
by eloff 5y ago
One case where this is useful is where you want determinism. You don't need a particular order, but you do need it to be consistent.
This comes up a lot in compilers where you don't want the output code to vary on each run.
This is specifically a big problem with Go, because maps use random iteration order so you don't depend on it. I feel that was a mistake. I would rather they took a page from Python and JavaScript and used insertion order. The reason they did not was to avoid painting themselves into a corner with respect to algorithms and options in the future - which is reasonable.
Rust uses a randomly seeded hash algorithm on purpose to defend against hash DOS attacks.
Hashing doesn't necessarily mean indeterminate, outside of Go and Rust, but it can be tricky to guarantee because it depends on the algorithm and the memory allocator (which is often multithreaded and can introduce non deterministic behavior.)
- echelon 5y agoMaybe it wasn't your intent (I also could be reading this wrong), but I feel like throwing Rust under the bus here is unfair. Rust has a ton of different collections types you can use. You can also replace the hashing and seeding algorithms. It's the most flexible of the lot out of necessity. Systems programming requires fine control over data structures.
- eloff 5y ago> Maybe it wasn't your intent (I also could be reading this wrong), but I feel like throwing Rust under the bus here is unfair. I don't see how that was throwing rust under the bus. I didn't even state my opinion, just the fact that it makes this performance for safety tradeoff (an unusual one since most hash tables do not attempt to protect against hash DOS attacks.) You can replace the hashing algorithm. The rust compiler does this. But most people don't fiddle with the default, which makes it a questionable decision in my books.
- _nalply 5y agoThrowing Rust under the bus...? I don't think that anyone really could do that. I am chuckling as I am writing this.