Sorting is a state and a verb (and a floor wax and a dessert topping)

Raymond Chen

Raymond

Cliff Barbier points out that

after you sort an Explorer view
by name, new items are not inserted in their sorted position
.
This goes back to the question of whether sorting is a state or a verb.

If you take an Explorer folder and say Sort by Name,
do you mean
“From now on, always show the contents of this folder sorted by name”?
Or do you mean
“Rearrange the items currently in this folder so they are sorted by name”?
The first case treats sorting a state,
where sorting is an attribute of the folder that persists.
The second case treats sorting as a verb,
where the action is performed so that its effects linger but the action
itself is not remembered.

You might think that sorting is obviously a state,
but STL disagrees with you:

std::vector<Item> v;
... fill v with stuff ...
std::sort(v.begin(), v.end(), Item::ByName);
v.push_back(Item(...));

When the last line of code appends a new item to the vector,
it is not inserted in sorted order because std::sort
is a verb which acts on the vector, not a state of the vector itself.
The vector doesn’t know “Oh, wait, I’m now a sorted vector.”

Okay, so in Explorer, is sorting a state or a verb?

Let’s do both!”

Sorting is a state, in the sense that the list of items is presented
in sorted order when the folder is first opened.
It’s a verb in that the sorted order is not maintained when new items
are added to the view while the folder is already open.

Placing new items at the end instead of in their sorted position is
necessary to avoid having items move around unbidden.
Suppose you’re looking at a folder sorted by name,
you scroll down the list, find the item you want,
and just as your finger is posed to click the mouse button,
another process creates a file in the folder,
which Explorer picks up and inserts into the view,
causing the items to shift,
and when your finger goes down on the mouse button,
you end up clicking on the wrong item.

You can imagine how annoying this can end up when there is a lot of
file creation activity in the folder.
If the items in the view were continuously sorted,
then they would keep moving around
and make it impossible to click on anything!

Mind you, you do have this instability problem when files are deleted
and you are in a non-placed view (like List or Details),
but there’s at least a cap on how much trouble deletion can cause
(since eventually you delete all the items that were in the view originally).

It looks like starting in Windows Vista,
Explorer tries to insert new items into their sorted position,
so at least in the modern versions of Windows, sort is a state.
Good luck trying to click on something when the contents of the folder
are constantly changing.

Raymond Chen
Raymond Chen

Follow Raymond   

0 comments

Comments are closed.