Please enable JavaScript.
Coggle requires JavaScript to display documents.
"Refactoring" by Martin Fowler (Chapter 3 - Bad smells in Code…
"Refactoring" by Martin Fowler
Chapter 1 - A first example: 60 pages
New features
Additional output: HTML
More kinds of plays
Coding conventions
Indefinite article in variable names
Name return value of a function "result"
Treat data as much as immutable as possible
Questions
What was your favourite refactoring?
What was your least favourite refactoring?
Performance vs Refactorings?
Is it really refactoring? (as new features are introduced as well)
What was new to you?
Your opinion on the baby steps?
Used refactorings
Extract Function ("switch")
Replace Temp with Query ("play")
Change Function Declaration ("remove play")
Inline Variable
Split loop
Slide Statements
Split phase ("divide logic into two parts")
Move Function
Replace Loop with Pipeline
Replace Conditional with Polymorphism
Replace Type Code with Subclasses
Replace Constructor with Factory Function
Refactoring steps
Decomposing into nested functions
Splitting phases of calculation & formatting
Reorganizing Calculations by Type
Key Learnings
Refactor with additional features in mind
Chapter 2 - Principles in Refactoring
Why refactor?
Refactoring improves the Design of Software
Makes Software easier to understand
Helps finding bugs
Helps program faster
Quotes
"If someone says their code was broken for a couple of days while they are refactoring, you can be pretty sure they were not refactoring."
"You have to refactor when you run into ugly code— but excellent code needs plenty of refactoring too."
“for each desired change, make the change easy (warning: this may be hard), then make the easy change”
“I’m not a great programmer; I’m just a good programmer with great habits.”
When refactor?
Rule of three
Preparatory Refactoring: Make it easier to add new features or fix bugs
Comprehension Refactoring: Make code easier to understand
Litter Pickup Refactoring
Planned and Opportunistic Refactoring
Definition
:
A change made to the internal structure of software to make it easier to understand and modify without changing its observable behaviour.
When not refactor?
Code that can be treated as API
Easier to rewrite
Chapter 3 - Bad smells in Code
Mysterious Name
Duplicated Code
Long Function & Large Class
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
Alternative Classes with Different Interfaces
Data Class
Refused Bequest
Comments
Chapter 4 - Building Tests
Make sure all tests are fully automatic and that they check their own results.
A suite of tests is a powerful bug detector that decapitates the time it takes to find bugs.
Always make sure a test will fail when it should.
Run tests frequently. Run those exercising the code you’re working on at least every few minutes; run all tests at least daily.
It is better to write and run incomplete tests than not to run complete tests.
Think of the boundary conditions under which things might go wrong and concentrate your tests there.
Don’t let the fear that testing can’t catch all bugs stop you from writing tests that catch most bugs.
When you get a bug report, start by writing a unit test that exposes the bug.
Chaper 6 - A First Set of Refactorings
Extract Function
Inline Function
Extract Variable
Inline Variable
Change Function Declaration
Encapsulate Variable
Rename Variable
Introduce Parameter Object
Combine Functions into Class
Combine Functions into Transform
Split Phase
Chapter 7 - Encapsulation
Encapsulate Record
Encapsulate Collection
Replace Primitive with Object
Replace Temp with Query
Extract Class
Inline Class
Hide Delegate
Remove Middle Man
Substitute Algorithm
Chapter 12 - Dealing with Inheritance
Pull Up Method
Pull Up Field
Pull Up Constructor Body
Push Down Method
Push Down Field
Replace Type Code with Subclasses
Remove Subclass
Extract Superclass
Collapse Hierarchy
Replace Subclass with Delegate
Replace Superclass with Delegate
Chapter 8 - Moving Features
Move Function
Move Field
Move Statements into Function
Move Statements to Callers
Replace Inline Code with Function Call
Slide Statements
Split Loop
Replace Loop with Pipeline
Remove Dead Code
Chapter 9 - Organizing Data
Split Variable
Rename Field
Replace Derived Variable with Query
Change Reference to Value
Change Value to Reference
Chapter 10 - Simplifying Conditional Logic
Decompose Conditional
Consolidate Conditional Expression
Replace Nested Conditional with Guard Clauses
Replace Conditional with Polymorphism
Introduce Special Case
INtroduce Assertion
Chapter 11 - Refactoring APIs
Separate Query from Modifier
Parametrize Function
Remove Flag Argument
Preserve Whole Object
Replace Parameter with Query
Replace Query with Parameter
Remove Setting Method
Replace Constuctir with Factory Function
Replace Function with Command
Replace Command with Function
Chapter 5 - Introducing the Catalog