{"id":9483,"date":"2019-06-26T13:11:18","date_gmt":"2019-06-26T13:11:18","guid":{"rendered":"https:\/\/www.uruit.com\/blog\/?p=9483"},"modified":"2023-05-31T01:49:43","modified_gmt":"2023-05-31T04:49:43","slug":"code-refactoring","status":"publish","type":"post","link":"https:\/\/uruit.com\/blog\/code-refactoring\/","title":{"rendered":"How to Make the Best of your Code with Refactoring"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_17 counter-hierarchy counter-decimal ez-toc-grey\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\">Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" style=\"display: none;\"><i class=\"ez-toc-glyphicon ez-toc-icon-toggle\"><\/i><\/a><\/span><\/div>\n<nav><ul class=\"ez-toc-list ez-toc-list-level-1\"><li class=\"ez-toc-page-1 ez-toc-heading-level-1\"><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/uruit.com\/blog\/code-refactoring\/#How_to_Make_the_Best_of_your_Code_with_Refactoring\" title=\"How to Make the Best of your Code with Refactoring\">How to Make the Best of your Code with Refactoring<\/a><ul class=\"ez-toc-list-level-3\"><li class=\"ez-toc-heading-level-3\"><ul class=\"ez-toc-list-level-3\"><li class=\"ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/uruit.com\/blog\/code-refactoring\/#What_is_refactoring\" title=\"What is refactoring?\">What is refactoring?<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/uruit.com\/blog\/code-refactoring\/#How_does_code_refactoring_benefit_my_team\" title=\"How does code refactoring benefit my team?\">How does code refactoring benefit my team?<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/uruit.com\/blog\/code-refactoring\/#Before_you_start%E2%80%A6\" title=\"Before you start&#8230;\">Before you start&#8230;<\/a><ul class=\"ez-toc-list-level-4\"><li class=\"ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/uruit.com\/blog\/code-refactoring\/#Prepare_your_system_for_safe_refactorings\" title=\"Prepare your system for safe refactorings\">Prepare your system for safe refactorings<\/a><\/li><\/ul><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/uruit.com\/blog\/code-refactoring\/#Where_do_I_begin\" title=\"Where do I begin?\">Where do I begin?<\/a><ul class=\"ez-toc-list-level-4\"><li class=\"ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/uruit.com\/blog\/code-refactoring\/#Your_tool_belt\" title=\"Your tool belt\">Your tool belt<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/uruit.com\/blog\/code-refactoring\/#Identifying_opportunities\" title=\"Identifying opportunities\">Identifying opportunities<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/uruit.com\/blog\/code-refactoring\/#Youre_not_alone\" title=\"You\u2019re not alone\">You\u2019re not alone<\/a><\/li><\/ul><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/uruit.com\/blog\/code-refactoring\/#When_is_it_a_good_time_to_do_code_refactoring\" title=\"When is it a good time to do code refactoring?\">When is it a good time to do code refactoring?<\/a><ul class=\"ez-toc-list-level-4\"><li class=\"ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/uruit.com\/blog\/code-refactoring\/#I_would_want_to_make_one_modification_to_that_statement\" title=\"I would want to make one modification to that statement:\u00a0\">I would want to make one modification to that statement:\u00a0<\/a><\/li><\/ul><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/uruit.com\/blog\/code-refactoring\/#Ready_to_make_the_best_of_your_codebase\" title=\"Ready to make the best of your codebase?\">Ready to make the best of your codebase?<\/a><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h1><span class=\"ez-toc-section\" id=\"How_to_Make_the_Best_of_your_Code_with_Refactoring\"><\/span><span data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;How to Make the Best of your Code with Refactoring&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:15231,&quot;3&quot;:{&quot;1&quot;:0},&quot;4&quot;:{&quot;1&quot;:2,&quot;2&quot;:16777215},&quot;5&quot;:{&quot;1&quot;:[{&quot;1&quot;:2,&quot;2&quot;:0,&quot;5&quot;:{&quot;1&quot;:2,&quot;2&quot;:0}},{&quot;1&quot;:0,&quot;2&quot;:0,&quot;3&quot;:3},{&quot;1&quot;:1,&quot;2&quot;:0,&quot;4&quot;:1}]},&quot;6&quot;:{&quot;1&quot;:[{&quot;1&quot;:2,&quot;2&quot;:0,&quot;5&quot;:{&quot;1&quot;:2,&quot;2&quot;:0}},{&quot;1&quot;:0,&quot;2&quot;:0,&quot;3&quot;:3},{&quot;1&quot;:1,&quot;2&quot;:0,&quot;4&quot;:1}]},&quot;7&quot;:{&quot;1&quot;:[{&quot;1&quot;:2,&quot;2&quot;:0,&quot;5&quot;:{&quot;1&quot;:2,&quot;2&quot;:0}},{&quot;1&quot;:0,&quot;2&quot;:0,&quot;3&quot;:3},{&quot;1&quot;:1,&quot;2&quot;:0,&quot;4&quot;:1}]},&quot;8&quot;:{&quot;1&quot;:[{&quot;1&quot;:2,&quot;2&quot;:0,&quot;5&quot;:{&quot;1&quot;:2,&quot;2&quot;:0}},{&quot;1&quot;:0,&quot;2&quot;:0,&quot;3&quot;:3},{&quot;1&quot;:1,&quot;2&quot;:0,&quot;4&quot;:1}]},&quot;9&quot;:0,&quot;11&quot;:3,&quot;12&quot;:0,&quot;14&quot;:{&quot;1&quot;:2,&quot;2&quot;:0},&quot;15&quot;:&quot;Calibri&quot;,&quot;16&quot;:11}\">How to Make the Best of your Code with Refactoring<\/span><span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p><span style=\"font-weight: 400;\">In the early days of software, a system was thoroughly designed before you even put down the first line of code. Days went by making diagrams, outlining use cases, and charting estimates. By the time you started development, you had a long, meticulous blueprint of your system. You would feel, this time, you really got something special.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">But as time passed, the design became stale. Soon, every piece of functionality meant an entirely new module with hundreds of lines of repeated code, and the code you wrote a month ago doesn\u2019t make sense anymore. In short, the spark faded and you no longer loved your code like you used to.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Modern, agile software development paints a new picture of this relationship. <strong>Today, code design is flexible and constantly evolving and at the core of the process, we find refactoring.<\/strong><\/span><\/p>\n<h3><span class=\"ez-toc-section\" id=\"What_is_refactoring\"><\/span>What is refactoring?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><img loading=\"lazy\" class=\"aligncenter wp-image-9484 size-full\" src=\"https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre2.jpg\" alt=\"code refactoring\" width=\"2480\" height=\"1772\" srcset=\"https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre2.jpg 1920w, https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre2-300x214.jpg 300w, https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre2-1024x732.jpg 1024w, https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre2-768x549.jpg 768w, https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre2-1536x1097.jpg 1536w, https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre2-2048x1463.jpg 2048w, https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre2-750x536.jpg 750w, https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre2-1140x815.jpg 1140w, https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre2-20x14.jpg 20w\" sizes=\"(max-width: 2480px) 100vw, 2480px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">In short, <strong>refactoring means restructuring existing code without changing the output<\/strong>. You may have heard the term \u201crefactoring\u201d used vaguely to refer to any modification of existing code. However, refactoring is actually a technique based on well-defined transformations that improve your code without affecting the user-facing behavior.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Refactoring helps us keep our code fresh, easy to maintain and understandable across the entire lifespan of the system. Clean design and architecture are no longer a fixed destination that needs to be achieved before development; instead, it\u2019s a continuous journey.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">One important consideration is that refactoring doesn\u2019t intentionally fix bugs, alter any functionality or directly improve performance. The code is assumed to be in a working state before you start. In addition, the moment you change any observable behavior, you\u2019ve stopped refactoring and entered the realm of debugging, feature development or performance optimization.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Put in layman\u2019s terms, refactoring is similar to restating or paraphrasing a text. What I mean is, you use different words to convey the same meaning in a clearer way, like adjusting the phrase, \u201cThe students didn\u2019t show any enthusiasm for the topic\u201d to \u201cThe students showed apathy towards the subject.\u201d<\/span><\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_does_code_refactoring_benefit_my_team\"><\/span>How does code refactoring benefit my team?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><span style=\"font-weight: 400;\">You may be wondering, then what\u2019s the benefit of refactoring? Why would I spend any time at all changing code that won\u2019t fix any bugs, add any functionality, or improve performance?\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Often, refactoring is thought of as \u201cperfectionism\u201d, changing code purely in the name of \u201cclean code\u201d, to reach the current best practices or follow the newest, buzz-worthiest architecture.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The truth is, refactoring is much more than that, and we do it purposefully. In fact, <strong>it can optimize resources, save time and money, and help teams meet their goals, so think of it as an investment.<\/strong> <\/span><\/p>\n<p><img loading=\"lazy\" class=\"aligncenter wp-image-9485 size-full\" src=\"https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre6.jpg\" alt=\"code refactoring\" width=\"2104\" height=\"1371\" srcset=\"https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre6.jpg 1920w, https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre6-300x195.jpg 300w, https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre6-1024x667.jpg 1024w, https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre6-768x500.jpg 768w, https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre6-1536x1001.jpg 1536w, https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre6-2048x1335.jpg 2048w, https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre6-750x489.jpg 750w, https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre6-1140x743.jpg 1140w, https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre6-20x13.jpg 20w\" sizes=\"(max-width: 2104px) 100vw, 2104px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">At my current project, even though our application is roughly a year old, refactoring is part of our culture. We continuously take the time to look back to the modules we use, maintain or need to extend, and enhance the design of the code when we find an opportunity. This doesn\u2019t mean we disapprove of the way things were made or that we consider it \u201cbad code\u201d. It just means we constantly improve ourselves as engineers and find a great benefit in translating that improvement into the code we\u2019ve written.<\/span><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Before_you_start%E2%80%A6\"><\/span>Before you start&#8230;<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Refactoring doesn\u2019t come without risk. After all, whenever we write code, we\u2019re prone to introducing bugs or causing serious performance setbacks. Therefore, this is why refactoring cannot be done by someone without any understanding of the code.<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><strong>The first step to safe refactoring is being aware of the subtle difference between refactoring and writing code that alters behavior.<\/strong> This doesn\u2019t really mean that refactoring should be thought of as a \u201cside project\u201d that you split from your main sprint cycles; on the contrary, you can constantly improve the code as you go.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">What this means is that, whenever you\u2019re adding functionality and find code that needs improvement, you should take a clear break from the new functionality and focus on applying refactoring. Once you improve the code, then you go back to adding functionality. This mindset change can happen several times a day. Also, it&#8217;s supported by a version control system and frequent commit cycles.<\/span><\/p>\n<h4><span class=\"ez-toc-section\" id=\"Prepare_your_system_for_safe_refactorings\"><\/span><span style=\"font-weight: 400;\">Prepare your system for safe refactorings<\/span><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p><span style=\"font-weight: 400;\">Normally, you\u2019d first want to have a comprehensive, well-written, trustworthy and automated test suite, based on behavior and decoupled from implementation.<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><strong>Refactorings, no matter how big or small, should always leave your tests in a passing state.<\/strong> Therefore, your system correctly working exactly as before. Automated testing running frequently will give you confidence that your users will be unaware of any modifications to the internal structure of your code and help you quickly find and prune bugs that you may inadvertently introduce while refactoring.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Testing also helps organize a clear set of expectations of the code, which helps other developers whenever they identify some that requires refactoring.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Another tool to establish expectations is written documentation, complemented by a clear and standard naming convention across your platform. Indeed, if you lack a naming convention and can\u2019t understand what a variable, method or class does by looking at the name, you have found the first opportunity for refactoring.<\/span><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Where_do_I_begin\"><\/span>Where do I begin?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><span style=\"font-weight: 400;\">When you\u2019ve set up the grounds for successful refactoring, a few tips will help you on your way:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\">\n<h4><span class=\"ez-toc-section\" id=\"Your_tool_belt\"><\/span><span style=\"font-weight: 400;\">Your tool belt<\/span><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Refactoring is not just naively changing code to make it \u201cbetter\u201d (which is a vague goal). <strong>In fact, there\u2019s actually a clear, defined set of transformations that you can apply.\u00a0<\/strong><\/span><\/p>\n<p><span style=\"font-weight: 400;\">Have you ever picked up a variable and modified the name to be more descriptive, then updated all the calls from the old name to the new one? This is called \u201cRename variable\u201d and is probably the most common refactoring there is. If you\u2019ve found a one-line function that was being used only once, and you eliminated this indirection by simply computing the variable inline, you\u2019ve applied \u201cInline function\u201d. If the function has no more uses, then you can apply \u201cRemove dead code\u201d to eliminate unnecessary definitions. These, and many other transformations, have a set of rules you can follow to guarantee a safe refactoring.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The trick is, you don\u2019t need to master every refactoring there is from the start. Instead, think of these transformations as individual tools that don\u2019t follow a specific order, but a specific need. You don\u2019t need to learn how to use a hammer in order to paint a wall.<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\">\n<h4><span class=\"ez-toc-section\" id=\"Identifying_opportunities\"><\/span><span style=\"font-weight: 400;\">Identifying opportunities<\/span><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">To understand which code needs refactoring and what transformation to apply, you\u2019ll often find people referring to \u201ccode smells\u201d. A \u201ccode smell\u201d is not just a gut feeling that something is wrong. It\u2019s actually a set of anti-patterns that usually lead to problems in software development, such as obscure, long methods or code that is repeated over and over again.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Code smells don\u2019t tell you what to do, but they\u2019re an indicator that something should be done. <strong>In identifying a code smell, you can also narrow down the set of transformations that you can apply to remedy the anti-pattern.<\/strong> For example, if you find a chunk of code repeated in a number of places (a problem known simply as Duplicate Code), you may want to try Extract Method, Extract Superclass, or Extract Class, patterns that fit the problem under different situations.\u00a0\u00a0<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\">\n<h4><span class=\"ez-toc-section\" id=\"Youre_not_alone\"><\/span><span style=\"font-weight: 400;\">You\u2019re not alone<\/span><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Refactoring as part of the development process is a mature and well-understood technique. Your IDE is probably already able to perform some safe, automated refactorings in your codebase, depending on your platform, such as renaming a variable (Rename Variable).<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Code review or peer programming is also a great way to identify opportunities and risks around refactoring. Bringing a new pair of eyes to the code is often a prime situation to detect code that smells and propose new patterns.<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><strong>The most comprehensive catalog where you can find a reference to every refactoring and code smell is probably the book \u201cRefactoring\u201d by Martin Fowler (2019)<\/strong> which also has an <\/span><a href=\"https:\/\/refactoring.com\/\" class=\"external\" rel=\"nofollow\"><span style=\"font-weight: 400;\">online version<\/span><\/a><span style=\"font-weight: 400;\">. If you\u2019re more of a course-oriented person, try their wonderful <\/span><span style=\"font-weight: 400;\">interactive course<\/span><span style=\"font-weight: 400;\"> created by Refactoring.Guru.<\/span><\/p>\n<h3><span class=\"ez-toc-section\" id=\"When_is_it_a_good_time_to_do_code_refactoring\"><\/span>When is it a good time to do code refactoring?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><span style=\"font-weight: 400;\">With all this in mind, it\u2019s important to understand not all \u201csmelly\u201d code requires refactoring. Like mentioned before, refactoring has risks, so it should always be done purposefully.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Once you find a case of \u201ccode smell\u201d, you may still want to take a few minutes or longer to ponder whether or not it\u2019s worth the time and risk. Some well-founded reasons to refactor are:<\/span><\/p>\n<p><img loading=\"lazy\" class=\"aligncenter size-full wp-image-9486\" src=\"https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre3.gif\" alt=\"\" width=\"1000\" height=\"715\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Have you ever had to add a new feature to an application that worked 90% just like another one, but couldn\u2019t reuse any of the previous code, so you just duplicated the module with menial changes? Or maybe a small bug took you a couple of weeks to figure out, then a one-line change to fix and an eight-line comment to explain? I know I have. Looking back to my initial days as a software engineer, I realize most of these experiences would have been a lot different if I had refactored first. I would take the time to understand the logic and capture that knowledge into an improved code structure before trying to add even more logic to muddy code.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In this spirit, Kent Beck, another prominent figure in the world of refactoring, dropped this piece of wisdom via his twitter account back in 2012:<\/span><\/p>\n<blockquote class=\"twitter-tweet\" data-lang=\"en\">\n<p dir=\"ltr\" lang=\"en\">for each desired change, make the change easy (warning: this may be hard), then make the easy change<\/p>\n<p>\u2014 Kent Beck (@KentBeck) <a href=\"https:\/\/twitter.com\/KentBeck\/status\/250733358307500032?ref_src=twsrc%5Etfw\" class=\"external\" rel=\"nofollow\">September 25, 2012<\/a><\/p><\/blockquote>\n<p><script async src=\"https:\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script><\/p>\n<h4><span class=\"ez-toc-section\" id=\"I_would_want_to_make_one_modification_to_that_statement\"><\/span><span style=\"font-weight: 400;\">I would want to make one modification to that statement:\u00a0<\/span><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p><a href=\"https:\/\/twitter.com\/KentBeck\/status\/250733358307500032\" class=\"external\" rel=\"nofollow\"><img loading=\"lazy\" class=\"wp-image-9487 size-full\" src=\"https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre5.jpg\" alt=\"\" width=\"2480\" height=\"650\" srcset=\"https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre5.jpg 1920w, https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre5-300x79.jpg 300w, https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre5-1024x268.jpg 1024w, https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre5-768x201.jpg 768w, https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre5-1536x403.jpg 1536w, https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre5-2048x537.jpg 2048w, https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre5-750x197.jpg 750w, https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre5-1140x299.jpg 1140w, https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre5-20x5.jpg 20w\" sizes=\"(max-width: 2480px) 100vw, 2480px\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400;\">Because sometimes you just don\u2019t need refactoring. You can avoid refactoring if:<\/span><\/p>\n<p><img loading=\"lazy\" class=\"aligncenter size-full wp-image-9488\" src=\"https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre4.gif\" alt=\"\" width=\"1000\" height=\"952\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Sometimes I run into any of these cases and still find it necessary to capture some understanding of the code. To do so, I trust means external to the code, such as documentation or a tutorial.<\/span><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Ready_to_make_the_best_of_your_codebase\"><\/span>Ready to make the best of your codebase?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><span style=\"font-weight: 400;\">An organized, clean software system requires consistent maintenance and a flexible perspective on the code and its structure. The traditional workflow of minutely planning the entire system ahead of time is evolving. We&#8217;re heading to a new, modern, agile workflow of incremental steps and continuous improvement. Based on this, developers can constantly improve and adapt code design.<\/span><\/p>\n<p><strong>Refactoring is a first-class citizen of modern development. It\u2019s distinct from, but complemented by, processes like debugging, feature development and performance tuning.<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">Now that you know that refactoring is not a vague idea of changing code in the name of perfectionism, but a structured set of tools and techniques to improve software design without modifying the observable behavior, you can start to lay in the groundwork for refactoring in favor of maintainability and scalability. To make it work, you need a comprehensive test suite, and clear expectations of the behavior.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">You can refactor as part of your normal, daily development process. To do so, you should count on a version control system that you can use to jump back to a working state should things get out of hand. Not all code can or should be refactored. So, I encourage you to take the time to consider the purpose of refactoring and weigh the risks before you dive in.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">And remember: <\/span><i><span style=\"font-weight: 400;\"><a href=\"https:\/\/uruit.com\/blog\/give-clean-code-the-importance-it-deserves\/\" class=\"broken_link\" rel=\"nofollow\">Clean code is a journey<\/a>, not a destination.\u00a0<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">Feel free to share this post wit<\/span><span style=\"font-weight: 400;\">h your colleagues \ud83d\ude42 We&#8217;d love to help more development teams with refactoring practices.<\/span><\/p>\n<p><img loading=\"lazy\" class=\"aligncenter size-full wp-image-9489\" src=\"https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre.jpg\" alt=\"code refactoring\" width=\"2480\" height=\"1772\" srcset=\"https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre.jpg 1920w, https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre-300x214.jpg 300w, https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre-1024x732.jpg 1024w, https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre-768x549.jpg 768w, https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre-1536x1097.jpg 1536w, https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre-2048x1463.jpg 2048w, https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre-750x536.jpg 750w, https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre-1140x815.jpg 1140w, https:\/\/uruit.com\/blog\/wp-content\/uploads\/2019\/06\/post-andre-20x14.jpg 20w\" sizes=\"(max-width: 2480px) 100vw, 2480px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Contents How to Make the Best of your Code with RefactoringWhat is refactoring?How does code refactoring benefit my team?Before you start&#8230;Prepare your system for safe refactoringsWhere do I begin?Your tool&#8230;<\/p>\n","protected":false},"author":34,"featured_media":9495,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[276],"tags":[],"_links":{"self":[{"href":"https:\/\/uruit.com\/blog\/wp-json\/wp\/v2\/posts\/9483"}],"collection":[{"href":"https:\/\/uruit.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/uruit.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/uruit.com\/blog\/wp-json\/wp\/v2\/users\/34"}],"replies":[{"embeddable":true,"href":"https:\/\/uruit.com\/blog\/wp-json\/wp\/v2\/comments?post=9483"}],"version-history":[{"count":6,"href":"https:\/\/uruit.com\/blog\/wp-json\/wp\/v2\/posts\/9483\/revisions"}],"predecessor-version":[{"id":11161,"href":"https:\/\/uruit.com\/blog\/wp-json\/wp\/v2\/posts\/9483\/revisions\/11161"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/uruit.com\/blog\/wp-json\/wp\/v2\/media\/9495"}],"wp:attachment":[{"href":"https:\/\/uruit.com\/blog\/wp-json\/wp\/v2\/media?parent=9483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/uruit.com\/blog\/wp-json\/wp\/v2\/categories?post=9483"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/uruit.com\/blog\/wp-json\/wp\/v2\/tags?post=9483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}