{"id":4991,"date":"2016-02-17T10:21:00","date_gmt":"2016-02-17T15:21:00","guid":{"rendered":"http:\/\/irreal.org\/blog\/?p=4991"},"modified":"2016-02-17T13:48:14","modified_gmt":"2016-02-17T18:48:14","slug":"premature-optimization-and-bugs","status":"publish","type":"post","link":"https:\/\/irreal.org\/blog\/?p=4991","title":{"rendered":"Premature Optimization and Bugs"},"content":{"rendered":"<p> All developers are aware of Knuth&#8217;s warning about the dangers of premature optimization. Yesterday, I ran across two posts that nicely illustrate those dangers <i>in the wild<\/i>. <\/p>\n<p> The first is a tweet that explains why Unix files that begin with a dot are hidden\u2014that is, why they are not normally displayed by the <code>ls<\/code> command. That turns out to be a bug: the result of an optimization attempting to simplify a test for another condition. <\/p>\n<blockquote class=\"twitter-tweet\" data-conversation=\"none\" data-lang=\"en\">\n<p lang=\"en\" dir=\"ltr\">Reminder: the origin of hidden files is a bug<a href=\"https:\/\/t.co\/5zAOYOu1CA\">https:\/\/t.co\/5zAOYOu1CA<\/a> <a href=\"https:\/\/t.co\/1RNVwKNP7l\">pic.twitter.com\/1RNVwKNP7l<\/a><\/p>\n<p>&mdash; Guillermo Rauch (@rauchg) <a href=\"https:\/\/twitter.com\/rauchg\/status\/698689290667053060\">February 14, 2016<\/a><\/p><\/blockquote>\n<p> <script async src=\"\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script><\/p>\n<p> The second is a post by Eric Raymond that explains how he was recently seduced by the siren song of <a href=\"http:\/\/esr.ibiblio.org\/?p=7027\">premature optimization<\/a>. He ended up with buggy, complicated code <del>that, as it turns out, was slower than doing the same task by the obvious brute force approach<\/del>. <\/p>\n<p> If you write code, you should definitely read these two items. They serve as an excellent reminder that even the masters can get tripped up when they optimize too early. That said, I&#8217;m sure I haven&#8217;t done it for the last time but at least we&#8217;re all warned. <\/p>\n<p> <b>UPDATE<\/b>: ESR <a href=\"http:\/\/irreal.org\/blog\/?p=4991#comment-2519753405\">wrote<\/a> to say that he hadn&#8217;t measured the relative speeds  of the two methods so I&#8217;ve deleted that part of the post. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>All developers are aware of Knuth&#8217;s warning about the dangers of premature optimization. Yesterday, I ran across two posts that nicely illustrate those dangers in the wild. The first is a tweet that explains why Unix files that begin with &hellip; <a href=\"https:\/\/irreal.org\/blog\/?p=4991\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[135],"class_list":["post-4991","post","type-post","status-publish","format-standard","hentry","category-programming","tag-programming"],"_links":{"self":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4991","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4991"}],"version-history":[{"count":3,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4991\/revisions"}],"predecessor-version":[{"id":4994,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4991\/revisions\/4994"}],"wp:attachment":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4991"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4991"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4991"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}