{"id":19133,"date":"2009-02-16T10:00:00","date_gmt":"2009-02-16T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2009\/02\/16\/dont-keep-track-of-information-you-dont-need\/"},"modified":"2009-02-16T10:00:00","modified_gmt":"2009-02-16T10:00:00","slug":"dont-keep-track-of-information-you-dont-need","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20090216-00\/?p=19133","title":{"rendered":"Don&#8217;t keep track of information you don&#8217;t need"},"content":{"rendered":"<p><P>\nThis is sort of an extreme corollary to\n<A HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2004\/12\/20\/327369.aspx\">\n<I>Don&#8217;t save anything you can recalculate<\/I><\/A>.\nSure, it sounds like such an obvious principle,\nbut many people fail to understand its consequences.\n<\/P>\n<P>\nLet&#8217;s look at the principle again.\n<I>Don&#8217;t keep track of information you don&#8217;t need<\/I>.\nI remember being asked to look at a customer&#8217;s program,\nand one thing that struck me was that the program had\na bazillion different flag variables that it spent a lot of time\nsetting and clearing. Here&#8217;s an oversimplified example:\n<\/P>\n<PRE>\nvoid CConfiguration::ShowDialog(HWND hwnd)\n{\n  m_fShowingDialog = true;\n  DoModal(hwnd);\n  m_fShowingDialog = false;\n  m_fDialogHasBeenShown = true;\n}\n<\/PRE>\n<P>\nA na&iuml;ve reading of the code would lead one to believe that\nthe main purpose of the program was to set and clear flags!\nUpon closer inspection, I found that most of the flag\nvariables were write-only.\nAlthough the code went to great pains to update the flags\nas it ran,\nthere was no code that actually cared whether the flag was set or not.\n<\/P>\n<P>\nI asked the customer liaison about this, thinking that maybe\nI missed something.\nMaybe the variables were being used in a subtle way that I failed\nto appreciate.\nMaybe they were used during debugging.\n<\/P>\n<P>\nThe customer liaison got back to me.\n&#8220;When I asked them about it, they just said, &#8216;Ah, yes.&#8217;\nApparently that code was written by one of their guys named Bob.\nI guess he likes to set and clear flags a lot.&#8221;\n<\/P>\n<P>\n<I>But is there any code that actually checks the values of those flags?<\/I>\n<\/P>\n<P>\n&#8220;Probably not.\nHe just set and cleared those flags because he figured maybe someday\nhe might need them.&#8221;\n<\/P>\n<P>\nIndeed, once in a while, he actually tested one of the dozens of flags\nhe spent most of his time setting and resetting.\nBut the vast majority of the flags were write-only.\n(And since most of the flags went unused,\nI suspect that many of them weren&#8217;t even accurate.)\n<\/P>\n<P>\nObviously, this is an extreme case of write-only variables,\nbut it illustrates the point.\nNext time, we&#8217;ll look at one of the consequences of the principle\nof not keeping track of information you don&#8217;t need.\n<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is sort of an extreme corollary to Don&#8217;t save anything you can recalculate. Sure, it sounds like such an obvious principle, but many people fail to understand its consequences. Let&#8217;s look at the principle again. Don&#8217;t keep track of information you don&#8217;t need. I remember being asked to look at a customer&#8217;s program, and [&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":[25],"class_list":["post-19133","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>This is sort of an extreme corollary to Don&#8217;t save anything you can recalculate. Sure, it sounds like such an obvious principle, but many people fail to understand its consequences. Let&#8217;s look at the principle again. Don&#8217;t keep track of information you don&#8217;t need. I remember being asked to look at a customer&#8217;s program, and [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/19133","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=19133"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/19133\/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=19133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=19133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=19133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}