3 ms·
https://go.dev/doc/go1#iteration https://go.dev/doc/go1#iteration > The old language specification did not define the order of iteration for maps, and in pract
by jhgg 2y ago
https://go.dev/doc/go1#iteration https://go.dev/doc/go1#iteration
> The old language specification did not define the order of iteration for maps, and in practice it differed across hardware platforms. This caused tests that iterated over maps to be fragile and non-portable, with the unpleasant property that a test might always pass on one machine but break on another.
> In Go 1, the order in which elements are visited when iterating over a map using a for range statement is defined to be unpredictable, even if the same loop is run multiple times with the same map. Code should not assume that the elements are visited in any particular order.
> This change means that code that depends on iteration order is very likely to break early and be fixed long before it becomes a problem. Just as important, it allows the map implementation to ensure better map balancing even when programs are using range loops to select an element from a mapl.