{"id":3016,"date":"2020-06-24T08:53:38","date_gmt":"2020-06-24T08:53:38","guid":{"rendered":"http:\/\/the-codest.localhost\/blog\/a-quick-primer-on-refactoring-for-beginners\/"},"modified":"2026-04-24T11:30:09","modified_gmt":"2026-04-24T11:30:09","slug":"a-quick-primer-on-refactoring-for-beginners","status":"publish","type":"post","link":"https:\/\/thecodest.co\/en\/blog\/a-quick-primer-on-refactoring-for-beginners\/","title":{"rendered":"A Quick Primer on Refactoring for Beginners"},"content":{"rendered":"\n<p>Therefore, it is incomprehensible for some that <strong>refactoring<\/strong> is actually an area of programming, and it is also a very important part of the programmer\u2019s work. The code is ever-evolving, it will be modified as long as there is the possibility of adding new functionalities. However, it may take a form that no longer allows for effectively adding new functionalities and it would be easier to rewrite the entire program.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is refactoring?<\/h2>\n\n\n\n<p>Usually, the answer you hear is that it is changing the structure of the code by applying a series of refactoring transformations without affecting the observable behavior of the code. This is true. Recently, I also came across a definition by <b>Martin Fowler<\/b> in his book <b>\u201cImproving the Design of Existing Code\u201d<\/b> where he describes <strong>refactoring<\/strong> as \u201cmaking big changes in small steps.\u201d He describes <strong>refactoring<\/strong> as a code change not affecting its operation, but he emphasizes that it has to be done in small steps.<\/p>\n\n\n\n<p>The book also advocates that <strong>refactoring<\/strong> does not affect the operation of the code and points out that it does not have any effect on passing the tests at any time. It describes step by step how to safely perform <strong>refactoring<\/strong>. I liked his book because it describes simple tricks that can be used in everyday work.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why do we need refactoring?<\/h2>\n\n\n\n<p>&nbsp;Most often, you may need it when you want to introduce a new functionality and the code in its current version does not allow it or it would be more difficult without changes to the code. Also, it is useful in cases when adding more features is unprofitable time-wise, that is, it would be faster to rewrite the code from scratch. I think it is sometimes forgotten that <strong>refactoring<\/strong> can make the code cleaner and more readable. Martin writes in his book how he performs refactoring when he feels unpleasant odors in the code and, how he puts it, <b>\u201cit always leaves room for the better\u201d<\/b>. And he surprised me here by seeing refactoring as an element of everyday code work. For me, the codes are often incomprehensible, reading it is a bit of experience as the code is often unintuitive.<\/p>\n\n\n\n<p>The distinguishing feature of a well-designed program is its <b>modularity<\/b>, thanks to which it is enough to know only a small part of the code to introduce most modifications. Modularity also makes it easier for new people to get in and start working more efficiently. To achieve this modularity, related program elements must be grouped together, the connections being understandable and easy to find. There is no single rule of thumb as to how this can be done. As you know and understand more and more of how the code is supposed to work better, you can group the elements, but sometimes you also have to test and check.<\/p>\n\n\n\n<p>One of the rules of refactoring in <b>YAGNI<\/b>, it is an acronym for \u2018You Aren\u2019t Gonna Need It\u2019 and stems from <b>eXtreme Programming (XP) <\/b>used mainly in <strong><a href=\"https:\/\/thecodest.co\/en\/blog\/how-to-implement-agile-methodology\/\">Agile<\/a> <a href=\"https:\/\/thecodest.co\/en\/blog\/8-key-questions-to-ask-your-software-development-outsourcing-partner\/\">software development<\/a> teams<\/strong>. Long story short, <b>YAGNI<\/b> says that only up-to-date stuff should be done. This basically means that even if something might be needed in the future, it shouldn\u2019t be done right now.&nbsp; But we also cannot crush further extensions and this is where modularity becomes important.<\/p>\n\n\n\n<p>When talking about <strong>refactoring<\/strong>, one of the most essential elements, i.e., tests, must be mentioned. In <strong>refactoring<\/strong>, we need to know that the code still works, because <strong>refactoring<\/strong> does not change how it works, but its structure, so all tests must be passed. It is best to run tests for the part of the code we are working on after each small transformation. It gives <a href=\"https:\/\/thecodest.co\/en\/blog\/why-us-companies-are-opting-for-polish-developers\/\">us<\/a> a confirmation that everything works as it should and it shortens the time of the whole operation. This is what Martin talks about in his book \u2013 run tests as often as possible so as not to take a step back and waste time looking for a transformation that broke something.<\/p>\n\n\n\n<p><strong><a href=\"https:\/\/thecodest.co\/en\/dictionary\/what-is-code-refactoring\/\">Code refactoring<\/a><\/strong> without testing is a pain and there&#8217;s a big chance that something will go wrong. If it is possible, it would be best to add at least some basic tests that will give us a little reassurance that the code works.<\/p>\n\n\n\n<p>The transformations listed below are only examples but they are really helpful in daily programing:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Function extraction and variable extraction \u2013 if the function is too long, check if there are any minor functions that could be extracted. The same goes for long lines. These transformations can help with finding duplications in the code. Thanks to Small Functions, the code becomes clearer and more understandable,<\/li>\n\n\n\n<li>Renaming of functions and variables \u2013 using the correct naming convention is essential to good programming. Variable names, when well-chosen, can tell a lot about the code,<\/li>\n\n\n\n<li>Grouping the functions into a class \u2013 this change is helpful when two classes perform similar operations as it can shorten the length of the class,<\/li>\n\n\n\n<li>Overriding the Nested Statement \u2013 if the condition checks out for a special case, issue a return statement when the condition occurs. These types of tests are often referred to as the guard clause. Replacing a Nested Conditional Statement with an Exit Statement changes the emphasis in the code. The if-else construct assigns equal weight to both variants. For the person reading the code, it is a message that each of them is equally probable and important,<\/li>\n\n\n\n<li>Introducing a special case \u2013 if you use some conditions in your code many times, it may be worth creating a separate structure for them. As a result, most special-case checks can be replaced with simple function calls. Often the common value that requires special processing is null. Therefore, this pattern is frequently called the Zero Object. However, this approach may be used in any special case,<\/li>\n\n\n\n<li>Replacement of the Conditional Instruction Polymorphism.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Example<\/h2>\n\n\n\n<p>This is an article about <strong>refactoring<\/strong> and an example is needed. I want to show a simple refactoring sample below with the use of <b>Overriding the Nested Statement<\/b> and <b>Replacement of the Conditional Instruction Polymorphism<\/b>. Let&#8217;s say we have a program function that returns a <a href=\"https:\/\/thecodest.co\/en\/blog\/hash-to-use-or-not-to-use\/\">hash<\/a> with information on how to water plants in real life. Such information would probably be in the model, but for this example, we have it in the function.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">def watering_info(plant)\n     result = {}\n     if plant.is_a? Suculent || plant.is_a? Cactus\n         result = { water_amount: \"A little bit \" , how_to: \"From the bottom\", watering_duration: \"2 weeks\" }\n     elsif plant.is_a? Alocasia || plant.is_a? Maranta\n         result = { water_amount: \"Big amount\", how_to: \"As you prefer\", watering_duration: \"5 days\" }\n     elsif plant.is_a? Peperomia\n         result = { water_amount: \"Dicent amount\",\n             how_to: \"From the bottom! they don't like water on the leaves\",\n             watering_duration: \"1 week\" }\n     else\n         result = { water_amount: \"Dicent amount\",\n             how_to: \"As you prefer\",\n             watering_duration: \"1 week\"\n             }\n     end\n     return result\n end\n<\/code><\/pre>\n\n\n\n<p>The idea is to change if to return:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"ruby\" class=\"language-ruby\">if plant.isa? Suculent || plant.isa? Cactus\n\n\u00a0\u00a0\u00a0\u00a0 result = { wateramount: \"A little bit \" , howto: \"From the bottom\",\n<\/code><\/pre>\n\n\n\n<p>To<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\"><code>return { water_amount: \"A little bit \" , how_to: \"From the bottom\",watering_duration: \"2 weeks\" } if plant.is_a? Suculent || plant.is_a? Cactus<\/code><\/code><\/pre>\n\n\n\n<p>return { water<em>amount: &#8220;A little bit &#8221; , how<\/em>to: &#8220;From the bottom&#8221;,watering<em>duration: &#8220;2 weeks&#8221; } if plant.is<\/em>a? Suculent || plant.is_a? Cactus<\/p>\n\n\n\n<p>And so on with everything, until we come to a function that looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">def watering_info(plant)\u00a0\u00a0\u00a0\u00a0\n\nreturn result = { wateramount: \"A little bit \" , howto: \"From the bottom\", wateringduration: \"2 weeks\" } if plant.isa? Suculent || plant.is_a? Cactus\n\nreturn result = { wateramount: \"Big amount\", howto: \"As you prefer\", wateringduration: \"5 days\" } if plant.isa? Alocasia || plant.is_a? Maranta\n\nreturn result = { water_amount: \"Dicent amount\",\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 howto: \"From the bottom! they don't like water on the leaves\",\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 wateringduration: \"1 week\" } if plant.is_a? Peperomia\n\nreturn result = { water_amount: \"Dicent amount\",\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 how_to: \"As you prefer\",\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 watering_duration: \"1 week\"\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\n\nend<\/code><\/pre>\n\n\n\n<p>\u00a0At the very end, we already had a return result. And a good habit is to do this step by step and test every change. You could replace this if block with a switch case and it would look better immediately, and you would not have to check all ifs every time. It would look like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">def watering_info(plant)\u00a0\u00a0\u00a0\u00a0\n\nswich plant.class.to_string\n\ncase Suculent, Cactus\n\n\u00a0\u00a0\u00a0\u00a0 { wateramount: \"A little bit \" , howto: \"From the bottom\", watering_duration: \"2 weeks\" }\n\ncase Alocasia, Maranta\n\n\u00a0\u00a0\u00a0\u00a0 { wateramount: \"Big amount\", howto: \"As you prefer\", watering_duration: \"5 days\" }\n\ncase Peperomia\n\n\u00a0\u00a0\u00a0\u00a0 { water_amount: \"Dicent amount\",\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 how_to: \"From the bottom! they don't like water on the leaves\",\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 watering_duration: \"1 week\" }\n\nelse\n\n\u00a0\u00a0\u00a0\u00a0 { water_amount: \"Dicent amount\",\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 how_to: \"As you prefer\",\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 watering_duration: \"1 week\u201d }\n\nend\n\nend<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>And then you can apply the <b>Replacing the Conditional Instruction Polymorphism<\/b>. This is to create a class with a function that returns the correct value and switches them in their proper places.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">class Suculent\n\n...\n\ndef watering_info()\n\n\u00a0\u00a0\u00a0\u00a0 return { wateramount: \"A little bit \" , howto: \"From the bottom\", watering_duration: \"2 weeks\" }\n\nend\n\nend\n\nclass Cactus\n\n...\n\ndef watering_info()\n\n\u00a0\u00a0\u00a0\u00a0 return { wateramount: \"A little bit \" , howto: \"From the bottom\", watering_duration: \"2 weeks\" }\n\nend\n\nend\n\nclass Alocasia\n\n...\n\ndef watering_info\n\n\u00a0\u00a0\u00a0\u00a0 return { wateramount: \"Big amount\", howto: \"As you prefer\", watering_duration: \"5 days\" }\n\nend\n\nend\n\nclass Maranta\n\n...\n\ndef watering_info\n\n\u00a0\u00a0\u00a0\u00a0 return { wateramount: \"Big amount\", howto: \"As you prefer\", watering_duration: \"5 days\" }\n\nend\n\nend\n\nclass Peperomia\n\n...\n\ndef watering_info\n\n\u00a0\u00a0\u00a0\u00a0 return { water_amount: \"Dicent amount\",\n\n\u00a0\u00a0\u00a0 \u00a0 how_to: \"From the bottom! they don't like water on the leaves\",\n\n\u00a0\u00a0\u00a0 \u00a0 watering_duration: \"1 week\" }\n\nend\n\nend\n\nclass Plant\n\n...\n\ndef watering_info\n\n\u00a0\u00a0\u00a0\u00a0 return { water_amount: \"Dicent amount\",\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 how_to: \"As you prefer\",\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 watering_duration: \"1 week\" }\n\nend\n\nend<\/code><\/pre>\n\n\n\n<p>And in the main watering_infofunction, the code will look like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">def watering_info(plant)\u00a0\u00a0\u00a0\u00a0\n\n\u00a0\u00a0\u00a0\u00a0plant.map(&amp;:watering_info)\n\nend<\/code><\/pre>\n\n\n\n<p>Of course, this function can be removed and replaced with its content. With this example, I wanted to present the general <strong>pattern of refactoring<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<p><strong>Refactoring<\/strong> is a big topic. I hope this article was an incentive to read more. These <strong>refactoring skills<\/strong> help you catch your bugs and improve your clean code workshop. I recommend reading Martin&#8217;s book (Improving the Design of Existing Code), which is a pretty basic and helpful set of rules of <strong>refactoring<\/strong>. The author shows various transformations step by step with a full explanation and motivation and tips on how to avoid mistakes in <strong>refactoring<\/strong>. Due to its versatility, it\u2019s a delightful book for frontend and <strong>backend developers<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/thecodest.co\/careers\"><img decoding=\"async\" src=\"\/app\/uploads\/2024\/05\/ruby_developer_hiring.jpeg\" alt=\"Become Junior Ruby Developer\"\/><\/a><\/figure>\n\n\n\n<p><strong>Read More<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/thecodest.co\/blog\/graphql-ruby-what-about-performance\">GraphQL Ruby. What about performance?<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/thecodest.co\/blog\/rails-and-other-means-of-transport\">Rails and Other Means of Transport<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/thecodest.co\/blog\/rails-development-with-tmux-vim-fzf-ripgrep\">Rails Development with TMUX, Vim, Fzf + Ripgrep<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Perhaps I am writing about something obvious to many, but maybe not to everyone. Refactoring is, I think, a complicated topic because it involves changing the code without affecting its operation.<\/p>\n","protected":false},"author":2,"featured_media":3017,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[8],"tags":[],"class_list":["post-3016","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software-development"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>A Quick Primer on Refactoring for Beginners - The Codest<\/title>\n<meta name=\"description\" content=\"Perhaps I am writing about something obvious to many, but maybe not to everyone. Refactoring is, I think, a complicated topic because it involves changing the code without affecting its operation.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/thecodest.co\/en\/blog\/a-quick-primer-on-refactoring-for-beginners\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"A Quick Primer on Refactoring for Beginners\" \/>\n<meta property=\"og:description\" content=\"Perhaps I am writing about something obvious to many, but maybe not to everyone. Refactoring is, I think, a complicated topic because it involves changing the code without affecting its operation.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/thecodest.co\/en\/blog\/a-quick-primer-on-refactoring-for-beginners\/\" \/>\n<meta property=\"og:site_name\" content=\"The Codest\" \/>\n<meta property=\"article:published_time\" content=\"2020-06-24T08:53:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-24T11:30:09+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/thecodest.co\/app\/uploads\/2024\/05\/regactor.png\" \/>\n\t<meta property=\"og:image:width\" content=\"960\" \/>\n\t<meta property=\"og:image:height\" content=\"540\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"thecodest\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"thecodest\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/a-quick-primer-on-refactoring-for-beginners\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/a-quick-primer-on-refactoring-for-beginners\\\/\"},\"author\":{\"name\":\"thecodest\",\"@id\":\"https:\\\/\\\/thecodest.co\\\/#\\\/schema\\\/person\\\/7e3fe41dfa4f4e41a7baad4c6e0d4f76\"},\"headline\":\"A Quick Primer on Refactoring for Beginners\",\"datePublished\":\"2020-06-24T08:53:38+00:00\",\"dateModified\":\"2026-04-24T11:30:09+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/a-quick-primer-on-refactoring-for-beginners\\\/\"},\"wordCount\":1338,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/a-quick-primer-on-refactoring-for-beginners\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/thecodest.co\\\/app\\\/uploads\\\/2024\\\/05\\\/regactor.png\",\"articleSection\":[\"Software Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/thecodest.co\\\/blog\\\/a-quick-primer-on-refactoring-for-beginners\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/a-quick-primer-on-refactoring-for-beginners\\\/\",\"url\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/a-quick-primer-on-refactoring-for-beginners\\\/\",\"name\":\"A Quick Primer on Refactoring for Beginners - The Codest\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/a-quick-primer-on-refactoring-for-beginners\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/a-quick-primer-on-refactoring-for-beginners\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/thecodest.co\\\/app\\\/uploads\\\/2024\\\/05\\\/regactor.png\",\"datePublished\":\"2020-06-24T08:53:38+00:00\",\"dateModified\":\"2026-04-24T11:30:09+00:00\",\"description\":\"Perhaps I am writing about something obvious to many, but maybe not to everyone. Refactoring is, I think, a complicated topic because it involves changing the code without affecting its operation.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/a-quick-primer-on-refactoring-for-beginners\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/thecodest.co\\\/blog\\\/a-quick-primer-on-refactoring-for-beginners\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/a-quick-primer-on-refactoring-for-beginners\\\/#primaryimage\",\"url\":\"https:\\\/\\\/thecodest.co\\\/app\\\/uploads\\\/2024\\\/05\\\/regactor.png\",\"contentUrl\":\"https:\\\/\\\/thecodest.co\\\/app\\\/uploads\\\/2024\\\/05\\\/regactor.png\",\"width\":960,\"height\":540},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/a-quick-primer-on-refactoring-for-beginners\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/thecodest.co\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"A Quick Primer on Refactoring for Beginners\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/thecodest.co\\\/#website\",\"url\":\"https:\\\/\\\/thecodest.co\\\/\",\"name\":\"The Codest\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/thecodest.co\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/thecodest.co\\\/#organization\",\"name\":\"The Codest\",\"url\":\"https:\\\/\\\/thecodest.co\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/thecodest.co\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/thecodest.co\\\/app\\\/uploads\\\/2024\\\/03\\\/thecodest-logo.svg\",\"contentUrl\":\"https:\\\/\\\/thecodest.co\\\/app\\\/uploads\\\/2024\\\/03\\\/thecodest-logo.svg\",\"width\":144,\"height\":36,\"caption\":\"The Codest\"},\"image\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/pl.linkedin.com\\\/company\\\/codest\",\"https:\\\/\\\/clutch.co\\\/profile\\\/codest\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/thecodest.co\\\/#\\\/schema\\\/person\\\/7e3fe41dfa4f4e41a7baad4c6e0d4f76\",\"name\":\"thecodest\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5dbfe6a1e8c86e432e8812759e34e6fe82ebac75119ae3237a6c1311fa19caf4?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5dbfe6a1e8c86e432e8812759e34e6fe82ebac75119ae3237a6c1311fa19caf4?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5dbfe6a1e8c86e432e8812759e34e6fe82ebac75119ae3237a6c1311fa19caf4?s=96&d=mm&r=g\",\"caption\":\"thecodest\"},\"url\":\"https:\\\/\\\/thecodest.co\\\/en\\\/author\\\/thecodest\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"A Quick Primer on Refactoring for Beginners - The Codest","description":"Perhaps I am writing about something obvious to many, but maybe not to everyone. Refactoring is, I think, a complicated topic because it involves changing the code without affecting its operation.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/thecodest.co\/en\/blog\/a-quick-primer-on-refactoring-for-beginners\/","og_locale":"en_US","og_type":"article","og_title":"A Quick Primer on Refactoring for Beginners","og_description":"Perhaps I am writing about something obvious to many, but maybe not to everyone. Refactoring is, I think, a complicated topic because it involves changing the code without affecting its operation.","og_url":"https:\/\/thecodest.co\/en\/blog\/a-quick-primer-on-refactoring-for-beginners\/","og_site_name":"The Codest","article_published_time":"2020-06-24T08:53:38+00:00","article_modified_time":"2026-04-24T11:30:09+00:00","og_image":[{"width":960,"height":540,"url":"https:\/\/thecodest.co\/app\/uploads\/2024\/05\/regactor.png","type":"image\/png"}],"author":"thecodest","twitter_card":"summary_large_image","twitter_misc":{"Written by":"thecodest","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/thecodest.co\/blog\/a-quick-primer-on-refactoring-for-beginners\/#article","isPartOf":{"@id":"https:\/\/thecodest.co\/blog\/a-quick-primer-on-refactoring-for-beginners\/"},"author":{"name":"thecodest","@id":"https:\/\/thecodest.co\/#\/schema\/person\/7e3fe41dfa4f4e41a7baad4c6e0d4f76"},"headline":"A Quick Primer on Refactoring for Beginners","datePublished":"2020-06-24T08:53:38+00:00","dateModified":"2026-04-24T11:30:09+00:00","mainEntityOfPage":{"@id":"https:\/\/thecodest.co\/blog\/a-quick-primer-on-refactoring-for-beginners\/"},"wordCount":1338,"commentCount":0,"publisher":{"@id":"https:\/\/thecodest.co\/#organization"},"image":{"@id":"https:\/\/thecodest.co\/blog\/a-quick-primer-on-refactoring-for-beginners\/#primaryimage"},"thumbnailUrl":"https:\/\/thecodest.co\/app\/uploads\/2024\/05\/regactor.png","articleSection":["Software Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/thecodest.co\/blog\/a-quick-primer-on-refactoring-for-beginners\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/thecodest.co\/blog\/a-quick-primer-on-refactoring-for-beginners\/","url":"https:\/\/thecodest.co\/blog\/a-quick-primer-on-refactoring-for-beginners\/","name":"A Quick Primer on Refactoring for Beginners - The Codest","isPartOf":{"@id":"https:\/\/thecodest.co\/#website"},"primaryImageOfPage":{"@id":"https:\/\/thecodest.co\/blog\/a-quick-primer-on-refactoring-for-beginners\/#primaryimage"},"image":{"@id":"https:\/\/thecodest.co\/blog\/a-quick-primer-on-refactoring-for-beginners\/#primaryimage"},"thumbnailUrl":"https:\/\/thecodest.co\/app\/uploads\/2024\/05\/regactor.png","datePublished":"2020-06-24T08:53:38+00:00","dateModified":"2026-04-24T11:30:09+00:00","description":"Perhaps I am writing about something obvious to many, but maybe not to everyone. Refactoring is, I think, a complicated topic because it involves changing the code without affecting its operation.","breadcrumb":{"@id":"https:\/\/thecodest.co\/blog\/a-quick-primer-on-refactoring-for-beginners\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/thecodest.co\/blog\/a-quick-primer-on-refactoring-for-beginners\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/thecodest.co\/blog\/a-quick-primer-on-refactoring-for-beginners\/#primaryimage","url":"https:\/\/thecodest.co\/app\/uploads\/2024\/05\/regactor.png","contentUrl":"https:\/\/thecodest.co\/app\/uploads\/2024\/05\/regactor.png","width":960,"height":540},{"@type":"BreadcrumbList","@id":"https:\/\/thecodest.co\/blog\/a-quick-primer-on-refactoring-for-beginners\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/thecodest.co\/"},{"@type":"ListItem","position":2,"name":"A Quick Primer on Refactoring for Beginners"}]},{"@type":"WebSite","@id":"https:\/\/thecodest.co\/#website","url":"https:\/\/thecodest.co\/","name":"The Codest","description":"","publisher":{"@id":"https:\/\/thecodest.co\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/thecodest.co\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/thecodest.co\/#organization","name":"The Codest","url":"https:\/\/thecodest.co\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/thecodest.co\/#\/schema\/logo\/image\/","url":"https:\/\/thecodest.co\/app\/uploads\/2024\/03\/thecodest-logo.svg","contentUrl":"https:\/\/thecodest.co\/app\/uploads\/2024\/03\/thecodest-logo.svg","width":144,"height":36,"caption":"The Codest"},"image":{"@id":"https:\/\/thecodest.co\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/pl.linkedin.com\/company\/codest","https:\/\/clutch.co\/profile\/codest"]},{"@type":"Person","@id":"https:\/\/thecodest.co\/#\/schema\/person\/7e3fe41dfa4f4e41a7baad4c6e0d4f76","name":"thecodest","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/5dbfe6a1e8c86e432e8812759e34e6fe82ebac75119ae3237a6c1311fa19caf4?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/5dbfe6a1e8c86e432e8812759e34e6fe82ebac75119ae3237a6c1311fa19caf4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5dbfe6a1e8c86e432e8812759e34e6fe82ebac75119ae3237a6c1311fa19caf4?s=96&d=mm&r=g","caption":"thecodest"},"url":"https:\/\/thecodest.co\/en\/author\/thecodest\/"}]}},"_links":{"self":[{"href":"https:\/\/thecodest.co\/en\/wp-json\/wp\/v2\/posts\/3016","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thecodest.co\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thecodest.co\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thecodest.co\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/thecodest.co\/en\/wp-json\/wp\/v2\/comments?post=3016"}],"version-history":[{"count":12,"href":"https:\/\/thecodest.co\/en\/wp-json\/wp\/v2\/posts\/3016\/revisions"}],"predecessor-version":[{"id":7707,"href":"https:\/\/thecodest.co\/en\/wp-json\/wp\/v2\/posts\/3016\/revisions\/7707"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/thecodest.co\/en\/wp-json\/wp\/v2\/media\/3017"}],"wp:attachment":[{"href":"https:\/\/thecodest.co\/en\/wp-json\/wp\/v2\/media?parent=3016"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thecodest.co\/en\/wp-json\/wp\/v2\/categories?post=3016"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thecodest.co\/en\/wp-json\/wp\/v2\/tags?post=3016"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}