## Metadata author:: Martin Fowler notable_authors:: Kent Beck isbn:: 978-0-13-475759-9 publish_date:: 1999-06-28 ## Chapter Notes ### Chapter 1 Refactoring: A First Example - First step in refactoring is to ensure that there is a solid set of tests for the section of code to ensure that functionality is not altered - Immediately compile/run the code after a change along with the test quite to check for unintended changes - Incrementally save and commit to VCS to easily return to prior state, squash merge later for the actual merge of the refactoring into [[git]] - Even if the result of a refactor is more loops and more loop iterations and what "appears" to be more inefficient code - sometimes the increased inefficiency is negligible or justifiably worth it for cleaner, simpler, more legible code. - If performance takes a big hit then it may warrant performance tuning after the refactor to try and speed it back up or even a revert of the refactor ### Chapter 2 - Refactoring is for when i need to understand the code base - If the code is a hot mess but i dont need to interact with it beyond treating it like an API black box then i can ignore the code for now. It's when i need to care that i refactor - If the code is easier to re-write than refactor that is also a valid edge case to not refactor - Client boundries can get in the way such as the published public interface - If we want people to avoid using the `circum()` function in favor of the `circumference()` function then like the example in [[124 Change Function Declaration]] leave the old declaration as a pass through with a deprecation warning and phase out over time. This is just the cost and fact of life for public interfaces and code ownership boundries. - reduce the complexity of large branch feature merges with things like feature toggles to turn off "in-progress" work that is unable to be broken into smaller parts in a ci-cd environment. ### Chapter 3 - Mysterious Name - [[124 Change Function Declaration]] - [[123 Inline Variable]] - [[137 Rename Variable]] - [[244 Rename Field]] - Duplicated Code - Long Function - Long Parameter List - Global Data - Mutable Data - Divergent Change - Shotgun Surgery - Feature Envy - Data Clumps - Primitive Obsession - Repeated Switches - Loops - Lazy Element - Speculative Generality - Temporary Field - Message Chains - Middle Man - Insider Trading - Large Class - Alternative Classes with Different Interfaces - Data Class - Refused Bequest - Comments ## Refactorings ![[106 Extract Function]] ![[123 Inline Variable]] ![[124 Change Function Declaration]] ![[132 Encapsulate Variable]] ![[137 Rename Variable]] ![[154 Split Phase]] ![[162 Encapsulate Record]] ![[178 Replace Temp With Query]] ![[198 Move Function]] ![[223 Slide Statements]] ![[227 Split Loop]] ![[231 Replace Loop With Pipeline]] ![[244 Rename Field]] ![[272 Replace Conditional With Polymorphism]] ![[310 Parameterize Function]] ![[334 Replace Constructor With Factory Function]] ![[362 Replace Type Code With Subclasses]]