{"id":10713,"date":"2011-05-09T07:00:00","date_gmt":"2011-05-09T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2011\/05\/09\/sorting-is-a-state-and-a-verb-and-a-floor-wax-and-a-dessert-topping\/"},"modified":"2011-05-09T07:00:00","modified_gmt":"2011-05-09T07:00:00","slug":"sorting-is-a-state-and-a-verb-and-a-floor-wax-and-a-dessert-topping","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20110509-00\/?p=10713","title":{"rendered":"Sorting is a state and a verb (and a floor wax and a dessert topping)"},"content":{"rendered":"<p>\nCliff Barbier points out that\n<a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2008\/08\/04\/8824356.aspx#8834347\">\nafter you sort an Explorer view\nby name, new items are not inserted in their sorted position<\/a>.\nThis goes back to the question of whether sorting is a state or a verb.\n<\/p>\n<p>\nIf you take an Explorer folder and say <i>Sort by Name<\/i>,\ndo you mean\n&#8220;From now on, always show the contents of this folder sorted by name&#8221;?\nOr do you mean\n&#8220;Rearrange the items currently in this folder so they are sorted by name&#8221;?\nThe first case treats sorting a state,\nwhere sorting is an attribute of the folder that persists.\nThe second case treats sorting as a verb,\nwhere the action is performed so that its effects linger but the action\nitself is not remembered.\n<\/p>\n<p>\nYou might think that sorting is obviously a state,\nbut STL disagrees with you:\n<\/p>\n<pre>\nstd::vector&lt;Item&gt; v;\n... fill v with stuff ...\nstd::sort(v.begin(), v.end(), Item::ByName);\nv.push_back(Item(...));\n<\/pre>\n<p>\nWhen the last line of code appends a new item to the vector,\nit is not inserted in sorted order because <code>std::sort<\/code>\nis a verb which acts on the vector, not a state of the vector itself.\nThe vector doesn&#8217;t know &#8220;Oh, wait, I&#8217;m now a sorted vector.&#8221;\n<\/p>\n<p>\nOkay, so in Explorer, is sorting a state or a verb?\n<\/p>\n<p>\n&#8220;<a HREF=\"http:\/\/dilbert.com\/strips\/comic\/1996-01-27\">Let&#8217;s do both<\/a>!&#8221;\n<\/p>\n<p>\nSorting is a state, in the sense that the list of items is presented\nin sorted order when the folder is first opened.\nIt&#8217;s a verb in that the sorted order is not maintained when new items\nare added to the view while the folder is already open.\n<\/p>\n<p>\nPlacing new items at the end instead of in their sorted position is\nnecessary to avoid having items move around unbidden.\nSuppose you&#8217;re looking at a folder sorted by name,\nyou scroll down the list, find the item you want,\nand just as your finger is posed to click the mouse button,\nanother process creates a file in the folder,\nwhich Explorer picks up and inserts into the view,\ncausing the items to shift,\nand when your finger goes down on the mouse button,\nyou end up clicking on the wrong item.\n<\/p>\n<p>\nYou can imagine how annoying this can end up when there is a lot of\nfile creation activity in the folder.\nIf the items in the view were continuously sorted,\nthen they would keep moving around\nand make it impossible to click on anything!\n<\/p>\n<p>\nMind you, you do have this instability problem when files are deleted\nand you are in a non-placed view (like List or Details),\nbut there&#8217;s at least a cap on how much trouble deletion can cause\n(since eventually you delete all the items that were in the view originally).\n<\/p>\n<p>\nIt looks like starting in Windows&nbsp;Vista,\nExplorer tries to insert new items into their sorted position,\nso at least in the modern versions of Windows, <i>sort<\/i> is a state.\nGood luck trying to click on something when the contents of the folder\nare constantly changing.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &#8220;From now on, always [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[26],"class_list":["post-10713","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-other"],"acf":[],"blog_post_summary":"<p>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 &#8220;From now on, always [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/10713","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=10713"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/10713\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=10713"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=10713"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=10713"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}