4 ms·
In golang it is purposefully randomized on every execution to prevent you from relying on iteration order
by TrinaryWorksToo 8y ago
In golang it is purposefully randomized on every execution to prevent you from relying on iteration order
- delhanty 8y agoThat's actually better than the situation in C. In C, debug `malloc` may very well behave the same run after run. Then you move into production, and release `malloc` behaves differently to debug `malloc`. Suddenly a latent bug that was there all along shows itself in release, but fails to reproduce in debug. With the randomized behavior you describe in golang, the bug probably will show in debug and be caught.
- wutbrodo 8y agoYea I wasn't sure enough to make a stronger claim, but I don't believe I've ever used ordered iteration of a hashtable. I feel like if I was tempted to do so, it would prompt me to rethink my design. Call it an "algorithm smell"