Download - Big code refactoring with agility
![Page 1: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/1.jpg)
HOW DO YOU HANDLE BIG REFACTORING WITH AGILE
METHODOLOGIES?
Luca Merolla
![Page 2: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/2.jpg)
What is code refactoring?
![Page 3: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/3.jpg)
“Process to change the existing code without changing its external behavior.
Refactoring improves nonfunctional attributes of the software”
CODE REFACTORING
![Page 4: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/4.jpg)
Why we need code refactoring?
![Page 5: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/5.jpg)
Some arguments :
❏ Quality❏ Code Clean❏ Better Design❏ Right Thing
WHY REFACTORING?
![Page 6: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/6.jpg)
Some arguments :
❏ Quality❏ Code Clean❏ Better Design❏ Right Thing
WHY REFACTORING?
Good Luck!
![Page 7: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/7.jpg)
The only “sellable” reason to do refactoring is
WHY REFACTORING?
![Page 8: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/8.jpg)
The only “sellable” reason to do refactoring is
WHY REFACTORING?
![Page 9: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/9.jpg)
The only “sellable” reason to do refactoring is
WHY REFACTORING?
Save money Faster to deliver new functionalities
![Page 10: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/10.jpg)
WHY REFACTORING?
![Page 11: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/11.jpg)
When to do refactoring?
![Page 12: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/12.jpg)
Ideally, when we identify:
❏ Code Smells: Things are not right
❏ WTFs: Code is not understandable
❏ It should be different: Product evolved
WHEN REFACTORING?
![Page 13: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/13.jpg)
Don’t clean up everything.
It should be a constant and gradual improvement
WHEN REFACTORING?
![Page 14: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/14.jpg)
Keep the balance between:refactoring vs new features
Don't refactor unless you think it will pay off later by allowing faster feature delivery
WHEN REFACTORING?
![Page 15: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/15.jpg)
How to do refactoring?<
![Page 16: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/16.jpg)
From the methodology point of view, my experience tells me that:
❏ Revolutionary design is evil
❏ Evolutionary design is good
HOW TO REFACTOR?
![Page 17: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/17.jpg)
The most common approaches about refactoring are:
❏ “Big Bang”
❏ “Divide and Conquer”
❏ Planned refactoring
HOW TO REFACTOR?
![Page 18: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/18.jpg)
The “Big Bang” approach:❏ Define a new structure for your code❏ Move the code to the new structure❏ Rebuild the puzzle❏ Make tests green again!
HOW TO REFACTOR?
![Page 19: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/19.jpg)
The “Big Bang” approach:❏ Define a new structure for your code❏ Move the code to the new structure❏ Rebuild the puzzle❏ Make tests green again!
HOW TO REFACTOR?
❏ High risks!❏ Almost like rewrite from scratch
![Page 20: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/20.jpg)
The “Divide and Conquer” approach:❏ Define a Vision❏ Break the application into pieces❏ Rebuild the puzzle❏ Make tests green again!
HOW TO REFACTOR?
![Page 21: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/21.jpg)
The “Divide and Conquer” approach:❏ Define a Vision❏ Break the application into pieces❏ Rebuild the puzzle❏ Make tests green again!
HOW TO REFACTOR?
❏ Difficult estimation (like bugs)❏ Code could be “undeliverable” for
long period
![Page 22: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/22.jpg)
Planned Refactoring also called as Stabilization periods:❏ No new features developed (Code freeze period)❏ Work without adding Value❏ Not an improvement for the customer
HOW TO REFACTOR?
![Page 23: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/23.jpg)
Planned Refactoring also called as Stabilization periods:❏ No new features developed (Code freeze period)❏ Work without adding Value❏ Not an improvement for the customer
HOW TO REFACTOR?
❏ It’s a Methodology Smell!❏ No real “value” added to the
application
![Page 24: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/24.jpg)
What a Good Team does is:❏ Define a Vision❏ Break it into smaller tasks❏ Refactoring all the time (part of regular work)❏ Responsible (Diligently keep the code clean)
HOW TO REFACTOR?
![Page 25: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/25.jpg)
What a Good Team does is:❏ Define a Vision❏ Break it into smaller tasks❏ Refactoring all the time (part of regular work)❏ Responsible (Diligently keep the code clean)
HOW TO REFACTOR?
❏ Code can be delivered (often)❏ New features benefits from the
refactor (faster to develop)
![Page 26: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/26.jpg)
How much refactoring should we be doing?
<
![Page 27: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/27.jpg)
HOW MUCH REFACTOR?
We need to always consider the benefits of refactoring❏ Tolerance level (metrics could help)❏ Don’t clean up everything❏ Make refactoring part of our daily work❏ Multiple small improvements❏ Don’t refactor what is not likely to change❏ Consider the economic factor:
Cleaner code ⇨ Quicker and Cheaper changes
![Page 28: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/28.jpg)
How can we obtain Refactoring with Agile
Methodologies?
![Page 29: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/29.jpg)
Agile Methodologies focuses on continuous (or at least frequent) Value delivery.
The Value (for the customer) is realized when the product is shipped in production, not before.
AGILE & REFACTOR?
![Page 30: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/30.jpg)
In order to use Agile Methodologies for big refactoring, we need to enforce some practices:
❏ Define and communicate the Vision
❏ Start with small tasks
❏ Iterate and Learn
AGILE & REFACTOR?
![Page 31: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/31.jpg)
VISIONWhere to go MUST be clear.
![Page 32: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/32.jpg)
Small Steps(Tasks) are
easier tohandle
![Page 33: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/33.jpg)
Iterate and Learn throughout the process
![Page 34: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/34.jpg)
Which Tools and Techniques should we use?
![Page 35: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/35.jpg)
There are different tools and techniques that can help us to be more agile and deliver more often:
❏ Trunk Based Development
❏ Branch By Abstraction
❏ Feature Toggles/Flags
TOOLS & TECHNIQUES
![Page 36: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/36.jpg)
What is Trunk Based Development?
![Page 37: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/37.jpg)
Branches act as an Isolation from the “real world”.
TRUNK BASED DEV.
![Page 38: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/38.jpg)
Multi branchescan make the codeundeployable for long periods
TRUNK BASED DEV.
● Undeployable● Deployable
![Page 39: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/39.jpg)
What is really wrong with Branches?
❏ Branching is not bad, long lived branches are bad
❏ “Isolation” for prolonged periods of time is bad
❏ Multi-branches can lead to undeployable code
TRUNK BASED DEV.
![Page 40: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/40.jpg)
How does TBD look like?
TRUNK BASED DEV.
![Page 41: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/41.jpg)
What are the benefits of TBD?❏ Work on a single shared trunk❏ Always work against the latest code❏ Merge and integration pain is minimised
Note:❏ TBD does not prohibit branching
TRUNK BASED DEV.
![Page 42: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/42.jpg)
TRUNK BASED DEV.
TRUNK209 210 211R D ?
TRUNK209 210 211R D ?
209.xFIX
R
209.1
F
D ?
R RELEASED
DEVELOPED NO COMMITS YET
F FIXTBD Optimistic Branching
![Page 43: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/43.jpg)
TRUNK BASED DEV.
D ?
R RELEASED
DEVELOPED NO COMMITS YET
F FIXTBD Pessimistic Branching
TRUNK209 210 211R D
209.x
TRUNK209 210 211R D
209.xFIX
R
209.1
F
TRUNK209 210 211R D ?
209.x?
R
211.x?
R
211.x?
![Page 44: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/44.jpg)
What is Branch By Abstraction?
![Page 45: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/45.jpg)
BRANCH BY ABSTRACTION
1. Introduce an abstraction layer
2. Update all the code to rely on the abstraction
3. Make new implementation of the abstraction
4. Remove the old implementation
![Page 46: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/46.jpg)
BRANCH BY ABSTRACTION
⇒
⇒
![Page 47: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/47.jpg)
What are feature toggles/flags?
![Page 48: Big code refactoring with agility](https://reader034.vdocuments.mx/reader034/viewer/2022051411/547e7ba6b379593a2b8b544d/html5/thumbnails/48.jpg)
TOGGLES & FLAGS?
What are the advantages of using Feature Toggles:
❏ Decouples code deployment from feature❏ No need to rollback (disable the feature)❏ A/B testing❏ Deliver features to specific users only❏ Continuous delivery