Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eager load constants in a consistent order #219

Merged
merged 1 commit into from
Jun 7, 2022

Conversation

casperisfine
Copy link
Contributor

The yield order of Dir.each_entry is directly dependent from the file system implementation. On macOS they will be yielded in alphabetical order, because that's how HFS is implemented.

However on Linux, different file system expose different orders. Most commonly, files are iterated with the last modified first, which across a fleet of server is akin to "random".

This small disrependency can cause order dependent code to fail. Arguably, it's the user code that is faulty and should be fixed (I agree), but even then, a predictable order makes it easier to debug.

For that same reason, since Ruby 3 Dir[] is sorted: https://bugs.ruby-lang.org/issues/8709

@fxn what do you think?

cc @jeromegn

The yield order of `Dir.each_entry` is directly dependent from the
file system implementation. On macOS they will be yielded in alphabetical
order, because that's how HFS is implemented.

However on Linux, different file system expose different orders. Most
commonly, files are iterated with the last modified first, which
across a fleet of server is akin to "random".

This small disrependency can cause order dependent code to fail.
Arguably, it's the user code that is faulty and should be fixed (I agree)
but even then, a predictable order makes it easier to debug.

For that same reason, since Ruby 3 `Dir[]` is sorted: https://bugs.ruby-lang.org/issues/8709
@fxn
Copy link
Owner

fxn commented Jun 7, 2022

I think this consistency is a good idea 👍.

@fxn fxn merged commit 5643e4a into fxn:main Jun 7, 2022
@casperisfine
Copy link
Contributor Author

Thanks Xavier!

@fxn
Copy link
Owner

fxn commented Jun 7, 2022

Managed to write at least one test for it 69fdf98.

This change is also helpful for log traces, I think. if someone shares code and logs that reproduce something to be debugged, they will be match yours (even in lazy mode).

@casperisfine
Copy link
Contributor Author

Managed to write at least one test for it

Ahaha thanks, I actually just threw the change quickly to start the discussion, I didn't expect you to merge it right away 😉

@fxn
Copy link
Owner

fxn commented Jun 7, 2022

@casperisfine absolutely :). I was ready to take it over, so just merged and did the rest for speed :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants