{"id":2858,"date":"2018-03-13T08:06:00","date_gmt":"2018-03-13T14:06:00","guid":{"rendered":"http:\/\/www.mooreds.com\/wordpress\/?p=2858"},"modified":"2018-03-13T08:06:00","modified_gmt":"2018-03-13T14:06:00","slug":"the-joy-of-removing-code","status":"publish","type":"post","link":"https:\/\/www.mooreds.com\/wordpress\/archives\/2858","title":{"rendered":"The joy of removing code"},"content":{"rendered":"<p>I am working on a project right now where my main task is to remove code. &#8220;What? I thought developers were supposed to add code, not remove it?&#8221; Well in some cases removing code actually can help a project. Some reasons to remove code: if the code doesn&#8217;t serve any purpose, if it isn&#8217;t executed, if it is for an edge case that never happens, if it has been superseded.<\/p>\n<p>Removing code is easier with automated tests, but I still find myself using a combination of automated tests, manual testing, and the find command. (This codebase is ruby, if I was using java I&#8217;d use the type system.) It&#8217;s painstaking work, but will be good in the end.<\/p>\n<p>My steps for removing code:<\/p>\n<ul>\n<li>Start with a plan and and end goal in mind. Otherwise it can get overwhelming if you are dealing with a system of any size.<\/li>\n<li>Create a feature branch<\/li>\n<li>Identify one piece of code you&#8217;re going to either remove or keep<\/li>\n<li>Make sure you know where it is called. If it isn&#8217;t called anywhere, remove it.<\/li>\n<li>Remove any tests and associated functionality (views, helpers, etc).<\/li>\n<li>Examine any state managed by the code for removal (database tables, etc)\n<ul>\n<li>Oftentimes I&#8217;ll just note that this should be removed in a few months, and focus on hiding the UX. It&#8217;s a lot easier to resurrect UX if you make a mistake than it is a dropped database table.<\/li>\n<\/ul>\n<\/li>\n<li>Commit the changes with a good commit message.<\/li>\n<li>Fan out from there and see if you need to add anything to your list.<\/li>\n<\/ul>\n<p>Take your time, don&#8217;t rush it.<\/p>\n<p>Code that never runs can&#8217;t have any bugs, and is super fast. Think about removing some code today.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am working on a project right now where my main task is to remove code. &#8220;What? I thought developers were supposed to add code, not remove it?&#8221; Well in [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,6],"tags":[],"class_list":["post-2858","post","type-post","status-publish","format-standard","hentry","category-dynamic-languages","category-programming"],"_links":{"self":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/2858","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/comments?post=2858"}],"version-history":[{"count":1,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/2858\/revisions"}],"predecessor-version":[{"id":2859,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/2858\/revisions\/2859"}],"wp:attachment":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/media?parent=2858"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/categories?post=2858"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/tags?post=2858"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}