Randomize the order of return in :GetChildren() [or provide a guarantee about the order]

The order of instances in the return value of GetChildren() is unspecified.

However, the order largely remains consistent, which can lead to subtle bugs when you assume that the order is consistent according to [some ordering].

While ROBLOX doesn’t guarantee the order of values, the actual order should be randomized so that these bugs aren’t so subtle.

This is something that the Go programming language has done with maps since almost the beginning; in order to dissuade programmers from depending on the order of iteration, the standard map object “randomizes” the order (I think in practice it only changes where iteration starts and perhaps the direction).

5 Likes

I just talked with @darthskrill abouut this yesterday. Currently :GetChildren() is consistent when deserializing and serializing to a file but it may not be consistent across the network. It sounds like we’re going to make the guarantee in the future that the order will be consistent even across the network.

11 Likes

I would assume FindFirstChild always corresponds correctly to the first index of GetChildren that has that name.