{"id":651,"date":"2014-11-19T00:41:04","date_gmt":"2014-11-19T05:41:04","guid":{"rendered":"http:\/\/www.rfdm.com\/blog\/?p=651"},"modified":"2014-11-19T02:23:09","modified_gmt":"2014-11-19T07:23:09","slug":"dont-do-this-to-your-software-team-example-1","status":"publish","type":"post","link":"https:\/\/www.rfdm.com\/blog\/?p=651","title":{"rendered":"Don&#8217;t do this to your software team, example 1"},"content":{"rendered":"<p>It&#8217;s been ages since I&#8217;ve posted to my blog.  But yesterday I found something in some code at work that prompted me to start a new set of posts.<\/p>\n<p>The following is an example of something gone awry and then never reviewed or repaired until someone &#8220;discovered&#8221; it (in this case, me).  Since the original author of this bit of code no longer works for the company, I am not aware of the motivation for this original form.  My best guess is that it was boilerplate code pasted into their editor of choice, then later committed without review or correction.  Here&#8217;s the original code:<\/p>\n<p><a href=\"https:\/\/www.rfdm.com\/blog\/wp-content\/uploads\/2014\/11\/BadCode.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.rfdm.com\/blog\/wp-content\/uploads\/2014\/11\/BadCode.png\" alt=\"BadCode\" width=\"599\" height=\"894\" class=\"alignnone size-full wp-image-657\" srcset=\"https:\/\/www.rfdm.com\/blog\/wp-content\/uploads\/2014\/11\/BadCode.png 599w, https:\/\/www.rfdm.com\/blog\/wp-content\/uploads\/2014\/11\/BadCode-201x300.png 201w\" sizes=\"auto, (max-width: 599px) 100vw, 599px\" \/><\/a><\/p>\n<p>There are a few troubling things about this code.  The first is that the logical equivalent, which I used to replace this code, is an easy to understand one-line function:<\/p>\n<p><a href=\"https:\/\/www.rfdm.com\/blog\/wp-content\/uploads\/2014\/11\/BadCodeReplacement.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.rfdm.com\/blog\/wp-content\/uploads\/2014\/11\/BadCodeReplacement.png\" alt=\"BadCodeReplacement\" width=\"463\" height=\"96\" class=\"alignnone size-full wp-image-659\" srcset=\"https:\/\/www.rfdm.com\/blog\/wp-content\/uploads\/2014\/11\/BadCodeReplacement.png 463w, https:\/\/www.rfdm.com\/blog\/wp-content\/uploads\/2014\/11\/BadCodeReplacement-300x62.png 300w\" sizes=\"auto, (max-width: 463px) 100vw, 463px\" \/><\/a><\/p>\n<p>The second troubling thing is that only a few seconds were required to recognize the bad code and its replacement, and another few to type in the replacement.  Even without my daily allowance of coffee, this falls into my 15-second refactoring category.<\/p>\n<p>The third troubling thing is the suppression of QAC message 6130.  QAC is a static analysis tool, one of several we use to find potential problems in our software.  Message 6130 is for cyclomatic complexity.  I&#8217;m not going to explain that here, I&#8217;m only going to point out that the general response to a warning from a static analysis tool should not be &#8220;Just suppress the warning.&#8221;<\/p>\n<p>The last troubling thing is the clearly incorrect comment associated with the suppression of the static analyzer warning.<\/p>\n<p>It&#8217;s easy to argue that any decent optimizing compiler would recognize the intent of the first version as being the same as the replacement, and produce equivalent assembly.  And in fact the compiler we use did just that.  That&#8217;s not the point.  The points are really simple:<\/p>\n<ul>\n<li>Don&#8217;t force yourself and your coworkers to read 38 lines of mostly superfluous code when they could just read 1 very easy line.<\/li>\n<li>Don&#8217;t throw a blanket over the warnings from your static analyzer.<\/li>\n<li>Don&#8217;t commit boilerplate code (including a boilerplate suppression of a static analyzer warning with a clearly incorrect comment) without at least reviewing it.  If it smells bad, it probably is bad, even if your static analyzer doesn&#8217;t flag it.  Ask for a second pair of eyes.  Make the code available for peer review.<\/li>\n<li>Don&#8217;t turn your brain off when putting comments in code.  A grossly incorrect comment is considerably worse than no comment at all.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s been ages since I&#8217;ve posted to my blog. But yesterday I found something in some code at work that prompted me to start a new set of posts. The following is an example of something gone awry and then never reviewed or repaired until someone &#8220;discovered&#8221; it (in this case, me). Since the original &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.rfdm.com\/blog\/?p=651\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Don&#8217;t do this to your software team, example 1&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-651","post","type-post","status-publish","format-standard","hentry","category-software-development"],"_links":{"self":[{"href":"https:\/\/www.rfdm.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/651","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rfdm.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rfdm.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rfdm.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rfdm.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=651"}],"version-history":[{"count":21,"href":"https:\/\/www.rfdm.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/651\/revisions"}],"predecessor-version":[{"id":678,"href":"https:\/\/www.rfdm.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/651\/revisions\/678"}],"wp:attachment":[{"href":"https:\/\/www.rfdm.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=651"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rfdm.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=651"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rfdm.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=651"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}