by eloff · 5y ago · 0 comments
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.)
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.
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.
I don't think that anyone really could do that. I am chuckling as I am writing this.