{"id":29853,"date":"2006-09-05T10:00:27","date_gmt":"2006-09-05T10:00:27","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2006\/09\/05\/just-change-that-15-to-a-1\/"},"modified":"2006-09-05T10:00:27","modified_gmt":"2006-09-05T10:00:27","slug":"just-change-that-15-to-a-1","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20060905-27\/?p=29853","title":{"rendered":"Just change that 15 to a 1"},"content":{"rendered":"<p>\n<a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2005\/11\/07\/489807.aspx#489918\">\nIt would be nice and easy to just change that 15 to a 1<\/a>.\n<\/p>\n<p>\nIf only it were that simple.\n<\/p>\n<p>\nIn the case described in that article, it&#8217;s not that a single\noperation was attempted fifteen times in a loop.\nRather, the fifteen operations were scattered all over the program.\nSuppose, for example, that the network operation was\n&#8220;Get the attributes of this file.&#8221;\nThe program might be filling in a file listing with several\ncolumns, one for the icon, another for the file name,\nanother for the file author, and the last one for the last-modified time.\n<\/p>\n<pre>\nfor each filename in directory {\n list.Add(new ListElement(filename));\n}\n<\/pre>\n<p>\nWell, that doesn&#8217;t access the same file fifteen times.\nOh wait, there&#8217;s more.\nWhat happens when it comes time to draw that list element?\n<\/p>\n<pre>\nListElement::DrawIcon()\n{\n if (m_whichIcon == don't know)\n {\n  m_whichIcon = GetIcon(m_filename);\n }\n draw the icon for the element\n}\n\/\/ with this common helper function\nGetIcon(filename)\n{\n if (filename is a directory) {\n  return FolderIcon;\n } else {\n  return PieceOfPaper;\n }\n}\n<\/pre>\n<p>\nOkay, getting the icon accesses the file once.\nYou can imagine a similar exercise for getting the file&#8217;s\nlast-modified time.\nWhat else?\n<\/p>\n<pre>\nListElement::GetAuthor()\n{\n if (m_author == don't know) {\n  AuthorProvider = LoadAuthorProvider();\n  m_author = AuthorProvider-&gt;GetFileAuthor(m_filename);\n }\n return m_author;\n}\n\/\/ where the author provider is implemented in a\n\/\/ separate component\nGetFileAuthor(filename)\n{\n if (filename is offline) {\n  return \"\";\n } else {\n  ... open the file and get the author ...\n }\n}\n<\/pre>\n<p>\nGetting the author accesses the file once to see if it\nis offline, then again to get the actual author (if the\nfile is online).\n<\/p>\n<p>\nSo in this simple sketch, we accessed the file a total\nof five times.\nIt&#8217;s not like there&#8217;s a 5 in this program you can change to a 1.\nRather, it&#8217;s a bunch of 1&#8217;s spread all over the place.\n(And one of the 1&#8217;s is in a separate component,\nthe hypothetical Author Provider.)\n<\/p>\n<p>\nIt reminds of a story I may have read in\nJohn Gall&#8217;s\n<i><a HREF=\"http:\/\/www.generalsystemantics.com\/Systemantics.htm\">Systemantics<\/a><\/i>:\nThere was a server product that was\nhaving problems under load.\nOnce there were more than thirty simultaneous users,\nthe system slowed to a crawl,\nbut the customer needed to support fifty users.\nAt a meeting convened to discuss this problem,\nan engineer joked,\n&#8220;Well, we just have to search the source code for\nthe <code>#define<\/code> that says thirty and change it to fifty.&#8221;\n<\/p>\n<p>\nAll the people at the meeting laughed, except one,\nwho earnestly asked, &#8220;Yeah, so why don&#8217;t we do that?&#8221;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It would be nice and easy to just change that 15 to a 1. If only it were that simple. In the case described in that article, it&#8217;s not that a single operation was attempted fifteen times in a loop. Rather, the fifteen operations were scattered all over the program. Suppose, for example, that the [&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-29853","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-other"],"acf":[],"blog_post_summary":"<p>It would be nice and easy to just change that 15 to a 1. If only it were that simple. In the case described in that article, it&#8217;s not that a single operation was attempted fifteen times in a loop. Rather, the fifteen operations were scattered all over the program. Suppose, for example, that the [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/29853","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=29853"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/29853\/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=29853"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=29853"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=29853"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}