ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:56274] [ruby-trunk - Bug #8709][Open] Dir.glob should return sorted file list
@ 2013-07-30 16:24 tommorris (Tom Morris)
  2013-07-30 17:49 ` [ruby-core:56275] [ruby-trunk - Bug #8709][Rejected] " charliesome (Charlie Somerville)
                   ` (17 more replies)
  0 siblings, 18 replies; 19+ messages in thread
From: tommorris (Tom Morris) @ 2013-07-30 16:24 UTC (permalink / raw)
  To: ruby-core


Issue #8709 has been reported by tommorris (Tom Morris).

----------------------------------------
Bug #8709: Dir.glob should return sorted file list
https://bugs.ruby-lang.org/issues/8709

Author: tommorris (Tom Morris)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 
ruby -v: ruby 1.9.3p429 (2013-05-15) [x86_64-linux] Brightbox
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN


On OS X, Dir.glob and Dir[] return an ordered list of files.

On Ubuntu Linux, they do not and one must manually sort them.

Returning a list of files that isn't in order fails the Principle of Least Astonishment.

I attach a unit test to demonstrate ideal behaviour.


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [ruby-core:56275] [ruby-trunk - Bug #8709][Rejected] Dir.glob should return sorted file list
  2013-07-30 16:24 [ruby-core:56274] [ruby-trunk - Bug #8709][Open] Dir.glob should return sorted file list tommorris (Tom Morris)
@ 2013-07-30 17:49 ` charliesome (Charlie Somerville)
  2020-01-11  6:28 ` [ruby-core:96776] [Ruby master Bug#8709] " rubybugsbmw
                   ` (16 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: charliesome (Charlie Somerville) @ 2013-07-30 17:49 UTC (permalink / raw)
  To: ruby-core


Issue #8709 has been updated by charliesome (Charlie Somerville).

Status changed from Open to Rejected

=begin
Dir.glob is documented to return filenames in filesystem order:

> Note that case sensitivity depends on your system, ((*as does the order in which the results are returned.*))
=end

----------------------------------------
Bug #8709: Dir.glob should return sorted file list
https://bugs.ruby-lang.org/issues/8709#change-40767

Author: tommorris (Tom Morris)
Status: Rejected
Priority: Normal
Assignee: 
Category: 
Target version: 
ruby -v: ruby 1.9.3p429 (2013-05-15) [x86_64-linux] Brightbox
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN


On OS X, Dir.glob and Dir[] return an ordered list of files.

On Ubuntu Linux, they do not and one must manually sort them.

Returning a list of files that isn't in order fails the Principle of Least Astonishment.

I attach a unit test to demonstrate ideal behaviour.


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [ruby-core:96776] [Ruby master Bug#8709] Dir.glob should return sorted file list
  2013-07-30 16:24 [ruby-core:56274] [ruby-trunk - Bug #8709][Open] Dir.glob should return sorted file list tommorris (Tom Morris)
  2013-07-30 17:49 ` [ruby-core:56275] [ruby-trunk - Bug #8709][Rejected] " charliesome (Charlie Somerville)
@ 2020-01-11  6:28 ` rubybugsbmw
  2020-01-11 11:18 ` [ruby-core:96779] " hsbt
                   ` (15 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: rubybugsbmw @ 2020-01-11  6:28 UTC (permalink / raw)
  To: ruby-core

Issue #8709 has been updated by bmwiedemann (Bernhard M. Wiedemann).

Status changed from Rejected to Open

There are two problems with unsorted glob:

1) it is different from glob in C, bash and perl that all sort by default. Even GNU make finally switched back to sorted wildcard/glob ( https://savannah.gnu.org/bugs/index.php?52076 )

2) it causes problems for reproducible builds, so that developers have to patch an infinite number of callers such as

https://github.com/sass/sassc-ruby/pull/178

to be able to get identical build results on identical OSes on different machines.

----------------------------------------
Bug #8709: Dir.glob should return sorted file list
https://bugs.ruby-lang.org/issues/8709#change-83770

* Author: tommorris (Tom Morris)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 1.9.3p429 (2013-05-15) [x86_64-linux] Brightbox
* Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN
----------------------------------------
On OS X, Dir.glob and Dir[] return an ordered list of files.

On Ubuntu Linux, they do not and one must manually sort them.

Returning a list of files that isn't in order fails the Principle of Least Astonishment.

I attach a unit test to demonstrate ideal behaviour.

---Files--------------------------------
globtest.rb (454 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [ruby-core:96779] [Ruby master Bug#8709] Dir.glob should return sorted file list
  2013-07-30 16:24 [ruby-core:56274] [ruby-trunk - Bug #8709][Open] Dir.glob should return sorted file list tommorris (Tom Morris)
  2013-07-30 17:49 ` [ruby-core:56275] [ruby-trunk - Bug #8709][Rejected] " charliesome (Charlie Somerville)
  2020-01-11  6:28 ` [ruby-core:96776] [Ruby master Bug#8709] " rubybugsbmw
@ 2020-01-11 11:18 ` hsbt
  2020-01-11 11:27 ` [ruby-core:96780] [Ruby master Feature#8709] " eregontp
                   ` (14 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: hsbt @ 2020-01-11 11:18 UTC (permalink / raw)
  To: ruby-core

Issue #8709 has been updated by hsbt (Hiroshi SHIBATA).

Backport deleted (1.9.3: UNKNOWN, 2.0.0: UNKNOWN)
Status changed from Open to Rejected

Do not update the `status` without a maintainer's decision.

----------------------------------------
Bug #8709: Dir.glob should return sorted file list
https://bugs.ruby-lang.org/issues/8709#change-83772

* Author: tommorris (Tom Morris)
* Status: Rejected
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 1.9.3p429 (2013-05-15) [x86_64-linux] Brightbox
* Backport: 
----------------------------------------
On OS X, Dir.glob and Dir[] return an ordered list of files.

On Ubuntu Linux, they do not and one must manually sort them.

Returning a list of files that isn't in order fails the Principle of Least Astonishment.

I attach a unit test to demonstrate ideal behaviour.

---Files--------------------------------
globtest.rb (454 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [ruby-core:96780] [Ruby master Feature#8709] Dir.glob should return sorted file list
  2013-07-30 16:24 [ruby-core:56274] [ruby-trunk - Bug #8709][Open] Dir.glob should return sorted file list tommorris (Tom Morris)
                   ` (2 preceding siblings ...)
  2020-01-11 11:18 ` [ruby-core:96779] " hsbt
@ 2020-01-11 11:27 ` eregontp
  2020-01-11 11:32 ` [ruby-core:96781] " hsbt
                   ` (13 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: eregontp @ 2020-01-11 11:27 UTC (permalink / raw)
  To: ruby-core

Issue #8709 has been updated by Eregon (Benoit Daloze).

ruby -v deleted (ruby 1.9.3p429 (2013-05-15) [x86_64-linux] Brightbox)
Status changed from Rejected to Open
Tracker changed from Bug to Feature

I agree always sorting the result of `Dir.glob` makes sense.
Non-determinism caused by Dir.glob is very annoying and IMHO doesn't feel like Ruby.
I would also expect sorting is a low overhead compared to syscalls, so performance-wise I think it's not a big hit.

FWIW, TruffleRuby currently returns sorted results for `Dir.glob`.

hsbt (Hiroshi SHIBATA) wrote:
> Do not update the `status` without a maintainer's decision.

How should we rediscuss this then?
It's not because the documentation mentions it we should never change it.
I'll reopen as a Feature.

----------------------------------------
Feature #8709: Dir.glob should return sorted file list
https://bugs.ruby-lang.org/issues/8709#change-83773

* Author: tommorris (Tom Morris)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
On OS X, Dir.glob and Dir[] return an ordered list of files.

On Ubuntu Linux, they do not and one must manually sort them.

Returning a list of files that isn't in order fails the Principle of Least Astonishment.

I attach a unit test to demonstrate ideal behaviour.

---Files--------------------------------
globtest.rb (454 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [ruby-core:96781] [Ruby master Feature#8709] Dir.glob should return sorted file list
  2013-07-30 16:24 [ruby-core:56274] [ruby-trunk - Bug #8709][Open] Dir.glob should return sorted file list tommorris (Tom Morris)
                   ` (3 preceding siblings ...)
  2020-01-11 11:27 ` [ruby-core:96780] [Ruby master Feature#8709] " eregontp
@ 2020-01-11 11:32 ` hsbt
  2020-01-11 11:33 ` [ruby-core:96782] " eregontp
                   ` (12 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: hsbt @ 2020-01-11 11:32 UTC (permalink / raw)
  To: ruby-core

Issue #8709 has been updated by hsbt (Hiroshi SHIBATA).


I have no opinion about this feature.

----------------------------------------
Feature #8709: Dir.glob should return sorted file list
https://bugs.ruby-lang.org/issues/8709#change-83774

* Author: tommorris (Tom Morris)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
On OS X, Dir.glob and Dir[] return an ordered list of files.

On Ubuntu Linux, they do not and one must manually sort them.

Returning a list of files that isn't in order fails the Principle of Least Astonishment.

I attach a unit test to demonstrate ideal behaviour.

---Files--------------------------------
globtest.rb (454 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [ruby-core:96782] [Ruby master Feature#8709] Dir.glob should return sorted file list
  2013-07-30 16:24 [ruby-core:56274] [ruby-trunk - Bug #8709][Open] Dir.glob should return sorted file list tommorris (Tom Morris)
                   ` (4 preceding siblings ...)
  2020-01-11 11:32 ` [ruby-core:96781] " hsbt
@ 2020-01-11 11:33 ` eregontp
  2020-01-11 11:35 ` [ruby-core:96785] " eregontp
                   ` (11 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: eregontp @ 2020-01-11 11:33 UTC (permalink / raw)
  To: ruby-core

Issue #8709 has been updated by Eregon (Benoit Daloze).


Here are some benchmark results in the ruby repository:
```
$ ruby -e 'p Dir["**/*"].size'
12171

$ ruby -rbenchmark -e '10.times { p Benchmark.realtime { Dir["**/*"] } }'     
0.017877419999422273
0.015390422999189468
0.015255956001055893
0.015021605999208987
0.015777969998453045
0.015484851002838695
0.016179073001694633
0.015210424000542844
0.015358253996964777
0.014319942998554325

$ ruby -rbenchmark -e '10.times { p Benchmark.realtime { Dir["**/*"].sort } }'
0.017600111998035572
0.017109740001615137
0.017832364999776473
0.01726310600133729
0.018130796997866128
0.01659841600121581
0.018173008000303525
0.017528833999676863
0.017515739000373287
0.01770434499849216
```

So a bit slower but we can likely optimize further if desired.

----------------------------------------
Feature #8709: Dir.glob should return sorted file list
https://bugs.ruby-lang.org/issues/8709#change-83776

* Author: tommorris (Tom Morris)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
On OS X, Dir.glob and Dir[] return an ordered list of files.

On Ubuntu Linux, they do not and one must manually sort them.

Returning a list of files that isn't in order fails the Principle of Least Astonishment.

I attach a unit test to demonstrate ideal behaviour.

---Files--------------------------------
globtest.rb (454 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [ruby-core:96785] [Ruby master Feature#8709] Dir.glob should return sorted file list
  2013-07-30 16:24 [ruby-core:56274] [ruby-trunk - Bug #8709][Open] Dir.glob should return sorted file list tommorris (Tom Morris)
                   ` (5 preceding siblings ...)
  2020-01-11 11:33 ` [ruby-core:96782] " eregontp
@ 2020-01-11 11:35 ` eregontp
  2020-01-11 20:48 ` [ruby-core:96792] " rubybugsbmw
                   ` (10 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: eregontp @ 2020-01-11 11:35 UTC (permalink / raw)
  To: ruby-core

Issue #8709 has been updated by Eregon (Benoit Daloze).


I added this issue to the next meeting's agenda:
https://bugs.ruby-lang.org/issues/16454

----------------------------------------
Feature #8709: Dir.glob should return sorted file list
https://bugs.ruby-lang.org/issues/8709#change-83779

* Author: tommorris (Tom Morris)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
On OS X, Dir.glob and Dir[] return an ordered list of files.

On Ubuntu Linux, they do not and one must manually sort them.

Returning a list of files that isn't in order fails the Principle of Least Astonishment.

I attach a unit test to demonstrate ideal behaviour.

---Files--------------------------------
globtest.rb (454 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [ruby-core:96792] [Ruby master Feature#8709] Dir.glob should return sorted file list
  2013-07-30 16:24 [ruby-core:56274] [ruby-trunk - Bug #8709][Open] Dir.glob should return sorted file list tommorris (Tom Morris)
                   ` (6 preceding siblings ...)
  2020-01-11 11:35 ` [ruby-core:96785] " eregontp
@ 2020-01-11 20:48 ` rubybugsbmw
  2020-01-13  9:28 ` [ruby-core:96823] " jean.boussier
                   ` (9 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: rubybugsbmw @ 2020-01-11 20:48 UTC (permalink / raw)
  To: ruby-core

Issue #8709 has been updated by bmwiedemann (Bernhard M. Wiedemann).


The benchmark numbers above show a difference of 12%

That is probably the worst case, because usually, globs will return fewer entries (though for some strange reason I get a 20% diff on a dir with 200 entries)

and usually some processing will be performed on the returned files and that will take much longer than the sorting.

----------------------------------------
Feature #8709: Dir.glob should return sorted file list
https://bugs.ruby-lang.org/issues/8709#change-83786

* Author: tommorris (Tom Morris)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
On OS X, Dir.glob and Dir[] return an ordered list of files.

On Ubuntu Linux, they do not and one must manually sort them.

Returning a list of files that isn't in order fails the Principle of Least Astonishment.

I attach a unit test to demonstrate ideal behaviour.

---Files--------------------------------
globtest.rb (454 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [ruby-core:96823] [Ruby master Feature#8709] Dir.glob should return sorted file list
  2013-07-30 16:24 [ruby-core:56274] [ruby-trunk - Bug #8709][Open] Dir.glob should return sorted file list tommorris (Tom Morris)
                   ` (7 preceding siblings ...)
  2020-01-11 20:48 ` [ruby-core:96792] " rubybugsbmw
@ 2020-01-13  9:28 ` jean.boussier
  2020-01-13 10:04 ` [ruby-core:96824] " deivid.rodriguez
                   ` (8 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: jean.boussier @ 2020-01-13  9:28 UTC (permalink / raw)
  To: ruby-core

Issue #8709 has been updated by byroot (Jean Boussier).


For what it's worth I also think it should return a sorted array, because:

  - Pretty much any rubyist I know have been been bitten by this at least once.
  - Many experienced rubyist end up always writing `Dir[patten].sort`
  - It's particularly prevalent because the "develop on OSX, deploy on Linux" combo is very popular.

If the performance impact is a concern, I think an extra keyword argument could be added: `glob( pattern, [flags], [base: path], [sort: true] )`, this way you can avoid the performance impact if you know that you don't need it.

----------------------------------------
Feature #8709: Dir.glob should return sorted file list
https://bugs.ruby-lang.org/issues/8709#change-83820

* Author: tommorris (Tom Morris)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
On OS X, Dir.glob and Dir[] return an ordered list of files.

On Ubuntu Linux, they do not and one must manually sort them.

Returning a list of files that isn't in order fails the Principle of Least Astonishment.

I attach a unit test to demonstrate ideal behaviour.

---Files--------------------------------
globtest.rb (454 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [ruby-core:96824] [Ruby master Feature#8709] Dir.glob should return sorted file list
  2013-07-30 16:24 [ruby-core:56274] [ruby-trunk - Bug #8709][Open] Dir.glob should return sorted file list tommorris (Tom Morris)
                   ` (8 preceding siblings ...)
  2020-01-13  9:28 ` [ruby-core:96823] " jean.boussier
@ 2020-01-13 10:04 ` deivid.rodriguez
  2020-01-13 18:49 ` [ruby-core:96828] " john
                   ` (7 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: deivid.rodriguez @ 2020-01-13 10:04 UTC (permalink / raw)
  To: ruby-core

Issue #8709 has been updated by deivid (David Rodríguez).


I got bit by this in the past too when trying to reproduce order dependent test failures (https://github.com/rubygems/rubygems/pull/2626#discussion_r254020218).

----------------------------------------
Feature #8709: Dir.glob should return sorted file list
https://bugs.ruby-lang.org/issues/8709#change-83821

* Author: tommorris (Tom Morris)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
On OS X, Dir.glob and Dir[] return an ordered list of files.

On Ubuntu Linux, they do not and one must manually sort them.

Returning a list of files that isn't in order fails the Principle of Least Astonishment.

I attach a unit test to demonstrate ideal behaviour.

---Files--------------------------------
globtest.rb (454 Bytes)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [ruby-core:96828] [Ruby master Feature#8709] Dir.glob should return sorted file list
  2013-07-30 16:24 [ruby-core:56274] [ruby-trunk - Bug #8709][Open] Dir.glob should return sorted file list tommorris (Tom Morris)
                   ` (9 preceding siblings ...)
  2020-01-13 10:04 ` [ruby-core:96824] " deivid.rodriguez
@ 2020-01-13 18:49 ` john
  2020-01-14  6:27 ` [ruby-core:96836] " naruse
                   ` (6 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: john @ 2020-01-13 18:49 UTC (permalink / raw)
  To: ruby-core

Issue #8709 has been updated by jhawthorn (John Hawthorn).


One potential issue with this is that though globs which scanned directories (ex. `Dir.glob("foo/*")`) would return results in an inconsistent order, globs which used purely brace expansion (ex. `Dir.glob("foo/{a,b,c,d}")`) would return values predictably in the order listed.

Rails versions prior to 6.0 unfortunately relied on this behaviour (6.0+ in *most* cases doesn't and does sorting manually). It probably shouldn't have relied on it, but it did, and I fear other libraries or tools may have done the same.

We could possibly work around that by sorting when reading directory entries rather than sorting the full result, but that's more complicated to implement and would be hard to document as an exact behaviour developers can expect/rely upon.

----------------------------------------
Feature #8709: Dir.glob should return sorted file list
https://bugs.ruby-lang.org/issues/8709#change-83826

* Author: tommorris (Tom Morris)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
On OS X, Dir.glob and Dir[] return an ordered list of files.

On Ubuntu Linux, they do not and one must manually sort them.

Returning a list of files that isn't in order fails the Principle of Least Astonishment.

I attach a unit test to demonstrate ideal behaviour.

---Files--------------------------------
globtest.rb (454 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [ruby-core:96836] [Ruby master Feature#8709] Dir.glob should return sorted file list
  2013-07-30 16:24 [ruby-core:56274] [ruby-trunk - Bug #8709][Open] Dir.glob should return sorted file list tommorris (Tom Morris)
                   ` (10 preceding siblings ...)
  2020-01-13 18:49 ` [ruby-core:96828] " john
@ 2020-01-14  6:27 ` naruse
  2020-01-14  7:27 ` [ruby-core:96840] " mame
                   ` (5 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: naruse @ 2020-01-14  6:27 UTC (permalink / raw)
  To: ruby-core

Issue #8709 has been updated by naruse (Yui NARUSE).


> the Principle of Least Astonishment.

You shouldn't use "the Principle of Least Astonishment".
Without the term you need to explain why the current behavior is bad and need to change.

For example ...
the result of Dir.glob depends a OS and filesystem. People often wrongly write code which depends their local environment.
Though people should carefully write portable code, could we provide a guard to protect people from such pitfalls?
Many people write specs which compare the result of Dir.glob and an expected array, and fails.
If Dir.glob sort the result, people can avoid pitfalls and reduce the cost of writing such specs.

----------------------------------------
Feature #8709: Dir.glob should return sorted file list
https://bugs.ruby-lang.org/issues/8709#change-83839

* Author: tommorris (Tom Morris)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
On OS X, Dir.glob and Dir[] return an ordered list of files.

On Ubuntu Linux, they do not and one must manually sort them.

Returning a list of files that isn't in order fails the Principle of Least Astonishment.

I attach a unit test to demonstrate ideal behaviour.

---Files--------------------------------
globtest.rb (454 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [ruby-core:96840] [Ruby master Feature#8709] Dir.glob should return sorted file list
  2013-07-30 16:24 [ruby-core:56274] [ruby-trunk - Bug #8709][Open] Dir.glob should return sorted file list tommorris (Tom Morris)
                   ` (11 preceding siblings ...)
  2020-01-14  6:27 ` [ruby-core:96836] " naruse
@ 2020-01-14  7:27 ` mame
  2020-01-14 10:40 ` [ruby-core:96850] " eregontp
                   ` (4 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: mame @ 2020-01-14  7:27 UTC (permalink / raw)
  To: ruby-core

Issue #8709 has been updated by mame (Yusuke Endoh).


Hi @jhawthorn, I'm unsure whether you agree with the proposal or not.  Do you mean sorting the result may break Rails?  Or not sorting the result may do so, i.e., are you against the change?

----------------------------------------
Feature #8709: Dir.glob should return sorted file list
https://bugs.ruby-lang.org/issues/8709#change-83843

* Author: tommorris (Tom Morris)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
On OS X, Dir.glob and Dir[] return an ordered list of files.

On Ubuntu Linux, they do not and one must manually sort them.

Returning a list of files that isn't in order fails the Principle of Least Astonishment.

I attach a unit test to demonstrate ideal behaviour.

---Files--------------------------------
globtest.rb (454 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [ruby-core:96850] [Ruby master Feature#8709] Dir.glob should return sorted file list
  2013-07-30 16:24 [ruby-core:56274] [ruby-trunk - Bug #8709][Open] Dir.glob should return sorted file list tommorris (Tom Morris)
                   ` (12 preceding siblings ...)
  2020-01-14  7:27 ` [ruby-core:96840] " mame
@ 2020-01-14 10:40 ` eregontp
  2020-01-14 10:44 ` [ruby-core:96851] " eregontp
                   ` (3 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: eregontp @ 2020-01-14 10:40 UTC (permalink / raw)
  To: ruby-core

Issue #8709 has been updated by Eregon (Benoit Daloze).


@jhawthorn Good point, I forgot to mention this.

The sorting must respect explicit order for `{...,...}` and conceptually the same as sorting just after readdir(3), not on the full result to be correct.
That's also likely more efficient, due to sorting smaller arrays.
ruby/spec already captures this, 3 specs fail if sorting is done on the returned array instead of per directory.

----------------------------------------
Feature #8709: Dir.glob should return sorted file list
https://bugs.ruby-lang.org/issues/8709#change-83855

* Author: tommorris (Tom Morris)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
On OS X, Dir.glob and Dir[] return an ordered list of files.

On Ubuntu Linux, they do not and one must manually sort them.

Returning a list of files that isn't in order fails the Principle of Least Astonishment.

I attach a unit test to demonstrate ideal behaviour.

---Files--------------------------------
globtest.rb (454 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [ruby-core:96851] [Ruby master Feature#8709] Dir.glob should return sorted file list
  2013-07-30 16:24 [ruby-core:56274] [ruby-trunk - Bug #8709][Open] Dir.glob should return sorted file list tommorris (Tom Morris)
                   ` (13 preceding siblings ...)
  2020-01-14 10:40 ` [ruby-core:96850] " eregontp
@ 2020-01-14 10:44 ` eregontp
  2020-01-16  5:22 ` [ruby-core:96882] " nobu
                   ` (2 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: eregontp @ 2020-01-14 10:44 UTC (permalink / raw)
  To: ruby-core

Issue #8709 has been updated by Eregon (Benoit Daloze).


Even C's glob(3) is sorted (by default), as @bmwiedemann said:

```
$ man 3 glob
...
       GLOB_NOSORT
              Don't sort the returned pathnames.  The only reason to do this is to save processing time.  By default, the returned path‐
              names are sorted.
```

----------------------------------------
Feature #8709: Dir.glob should return sorted file list
https://bugs.ruby-lang.org/issues/8709#change-83856

* Author: tommorris (Tom Morris)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
On OS X, Dir.glob and Dir[] return an ordered list of files.

On Ubuntu Linux, they do not and one must manually sort them.

Returning a list of files that isn't in order fails the Principle of Least Astonishment.

I attach a unit test to demonstrate ideal behaviour.

---Files--------------------------------
globtest.rb (454 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [ruby-core:96882] [Ruby master Feature#8709] Dir.glob should return sorted file list
  2013-07-30 16:24 [ruby-core:56274] [ruby-trunk - Bug #8709][Open] Dir.glob should return sorted file list tommorris (Tom Morris)
                   ` (14 preceding siblings ...)
  2020-01-14 10:44 ` [ruby-core:96851] " eregontp
@ 2020-01-16  5:22 ` nobu
  2020-01-16  6:03 ` [ruby-core:96888] " matz
  2020-01-16 15:12 ` [ruby-core:96911] " daniel
  17 siblings, 0 replies; 19+ messages in thread
From: nobu @ 2020-01-16  5:22 UTC (permalink / raw)
  To: ruby-core

Issue #8709 has been updated by nobu (Nobuyoshi Nakada).


I'm for adding `NOSORT` option to the second argument.

----------------------------------------
Feature #8709: Dir.glob should return sorted file list
https://bugs.ruby-lang.org/issues/8709#change-83894

* Author: tommorris (Tom Morris)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
On OS X, Dir.glob and Dir[] return an ordered list of files.

On Ubuntu Linux, they do not and one must manually sort them.

Returning a list of files that isn't in order fails the Principle of Least Astonishment.

I attach a unit test to demonstrate ideal behaviour.

---Files--------------------------------
globtest.rb (454 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [ruby-core:96888] [Ruby master Feature#8709] Dir.glob should return sorted file list
  2013-07-30 16:24 [ruby-core:56274] [ruby-trunk - Bug #8709][Open] Dir.glob should return sorted file list tommorris (Tom Morris)
                   ` (15 preceding siblings ...)
  2020-01-16  5:22 ` [ruby-core:96882] " nobu
@ 2020-01-16  6:03 ` matz
  2020-01-16 15:12 ` [ruby-core:96911] " daniel
  17 siblings, 0 replies; 19+ messages in thread
From: matz @ 2020-01-16  6:03 UTC (permalink / raw)
  To: ruby-core

Issue #8709 has been updated by matz (Yukihiro Matsumoto).


Accepted. We will add `sort: false` keyword option to disable sorting.

Matz.


----------------------------------------
Feature #8709: Dir.glob should return sorted file list
https://bugs.ruby-lang.org/issues/8709#change-83900

* Author: tommorris (Tom Morris)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
On OS X, Dir.glob and Dir[] return an ordered list of files.

On Ubuntu Linux, they do not and one must manually sort them.

Returning a list of files that isn't in order fails the Principle of Least Astonishment.

I attach a unit test to demonstrate ideal behaviour.

---Files--------------------------------
globtest.rb (454 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [ruby-core:96911] [Ruby master Feature#8709] Dir.glob should return sorted file list
  2013-07-30 16:24 [ruby-core:56274] [ruby-trunk - Bug #8709][Open] Dir.glob should return sorted file list tommorris (Tom Morris)
                   ` (16 preceding siblings ...)
  2020-01-16  6:03 ` [ruby-core:96888] " matz
@ 2020-01-16 15:12 ` daniel
  17 siblings, 0 replies; 19+ messages in thread
From: daniel @ 2020-01-16 15:12 UTC (permalink / raw)
  To: ruby-core

Issue #8709 has been updated by Dan0042 (Daniel DeLorme).


It's good to sort the result of `Dir["*"]`, but as jhawthorn pointed out the brace expansion _must_ keep the same order. I have code that depends on this, and I'm sure many others also have code that depend on this, since it's the behavior found in the shell:

     $ touch a2 a1 a0 b2 b1 b0
     $ echo {a,b}?
     a0 a1 a2 b0 b1 b2
     $ echo {b,a}?
     b0 b1 b2 a0 a1 a2


----------------------------------------
Feature #8709: Dir.glob should return sorted file list
https://bugs.ruby-lang.org/issues/8709#change-83929

* Author: tommorris (Tom Morris)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
On OS X, Dir.glob and Dir[] return an ordered list of files.

On Ubuntu Linux, they do not and one must manually sort them.

Returning a list of files that isn't in order fails the Principle of Least Astonishment.

I attach a unit test to demonstrate ideal behaviour.

---Files--------------------------------
globtest.rb (454 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2020-01-16 15:12 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-30 16:24 [ruby-core:56274] [ruby-trunk - Bug #8709][Open] Dir.glob should return sorted file list tommorris (Tom Morris)
2013-07-30 17:49 ` [ruby-core:56275] [ruby-trunk - Bug #8709][Rejected] " charliesome (Charlie Somerville)
2020-01-11  6:28 ` [ruby-core:96776] [Ruby master Bug#8709] " rubybugsbmw
2020-01-11 11:18 ` [ruby-core:96779] " hsbt
2020-01-11 11:27 ` [ruby-core:96780] [Ruby master Feature#8709] " eregontp
2020-01-11 11:32 ` [ruby-core:96781] " hsbt
2020-01-11 11:33 ` [ruby-core:96782] " eregontp
2020-01-11 11:35 ` [ruby-core:96785] " eregontp
2020-01-11 20:48 ` [ruby-core:96792] " rubybugsbmw
2020-01-13  9:28 ` [ruby-core:96823] " jean.boussier
2020-01-13 10:04 ` [ruby-core:96824] " deivid.rodriguez
2020-01-13 18:49 ` [ruby-core:96828] " john
2020-01-14  6:27 ` [ruby-core:96836] " naruse
2020-01-14  7:27 ` [ruby-core:96840] " mame
2020-01-14 10:40 ` [ruby-core:96850] " eregontp
2020-01-14 10:44 ` [ruby-core:96851] " eregontp
2020-01-16  5:22 ` [ruby-core:96882] " nobu
2020-01-16  6:03 ` [ruby-core:96888] " matz
2020-01-16 15:12 ` [ruby-core:96911] " daniel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).