large scale Refactoring
description
Transcript of large scale Refactoring
![Page 1: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/1.jpg)
Platinum Sponsor
LARGE SCALE REFACTORINGVolodymyr Fedak
![Page 2: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/2.jpg)
Who Am I
• Solution Architect at SoftServe with 9+ years experience in IT
• Ongoing project: Significant efforts are dedicated to the following quality attributes: testability, extensibility, maintainability
• A lot of efforts are spent on evolving legacy projects
![Page 3: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/3.jpg)
Why do we change
code?
Why refactor?
Refactoring strategies
Case study
Summary
Agenda
![Page 4: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/4.jpg)
Four Reasons to Change Software
Adding a feature
Fixing a bug
Improving the
design
Optimizing
resource usage
![Page 5: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/5.jpg)
Any fool can write code that a computer can understand. Good
programmers write code that humans can understand
![Page 6: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/6.jpg)
What is not refactoring
Refactoring is not debugging
Refactoring is not performance
Refactoring is not adding a feature
![Page 7: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/7.jpg)
"Refactoring is a disciplined
technique for restructuring an
existing body of code, altering its
internal structure without changing
its external behavior."
What is refactoring?
![Page 8: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/8.jpg)
Refactoring is an continuous process
![Page 9: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/9.jpg)
Restructuring of existing code that has visible
influence to the overall system quality attributes.
What is large scale refactoring?
![Page 10: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/10.jpg)
Why do we change
code?
Why refactor?
Refactoring strategies
Case study
Summary
Agenda
![Page 11: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/11.jpg)
Success projects statistics
![Page 12: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/12.jpg)
Legacy projects: technical perspective
![Page 13: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/13.jpg)
Legacy projects team policies and practices
They minimize the number of changes that they make to the
code baseSometimes this is a team policy: "If it's not broken, don't fix it”Developers
What? Create another method for that? No, I'll just put the lines of code right here in the method,
where I can see them and the rest of the code. It involves less
editing, and it's safer
![Page 14: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/14.jpg)
After such policy
![Page 15: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/15.jpg)
Refactoring helps
Make the code easier to understand
Make it easier to maintain codebase
Refactoring reduces your risk—can lead to lightweight pragmatic design
Improve code quality. You Can’t be Agile if your code sucks!
![Page 16: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/16.jpg)
Refactoring principles
Don’t write code that’s really not needed, Code you don’t write, don’t have to be maintained!
Avoid Clever Code—Keep it Simple
Keep code DRY
Rely on automated tests
![Page 17: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/17.jpg)
Refactoring principles
Checkin Frequently, take small steps
Make sense in seconds, not in minutes, hours, weeks, ...
Make code self documented
![Page 18: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/18.jpg)
Why do we change
code?
Why to refactor
workable code?
Refactoring strategies
Case study
Summary
Agenda
![Page 19: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/19.jpg)
Refactoring Catalog
![Page 20: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/20.jpg)
Mikado method
A change
We need to change this
![Page 21: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/21.jpg)
Mikado method
A change
When we changed this
![Page 22: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/22.jpg)
Prereq
Mikado method
A change
So it’s time to note all prerequisites
![Page 23: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/23.jpg)
PrereqPrereq
Mikado method
A change
So it’s time to note all prerequisites
![Page 24: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/24.jpg)
Prereq
PrereqPrereq
Mikado method
A change
So it’s time to note all prerequisites
![Page 25: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/25.jpg)
Prereq
PrereqPrereq
Mikado method
A change
When we tried refactor this
![Page 26: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/26.jpg)
Prereq
Prereq
Prereq
Mikado method
A change
We’ve got new errors
![Page 27: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/27.jpg)
Prereq
Prereq
Prereq
Prereq
Prereq
Mikado method
A change
Noted new prerequisites
![Page 28: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/28.jpg)
Prereq
Prereq
Prereq
Prereq
Prereq
Mikado method
A change
And reverted again
![Page 29: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/29.jpg)
Prereq
Prereq
Prereq
Prereq
Prereq
Mikado method
A change
Until we could do prerequisites without errors
![Page 30: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/30.jpg)
Prereq
Prereq
Prereq
Prereq
Prereq
Mikado method
A change
![Page 31: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/31.jpg)
Prereq
Prereq
Prereq
Prereq
Prereq
Mikado method
A change
Working the way back to original change
![Page 32: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/32.jpg)
Prereq
Prereq
Prereq
Prereq
Prereq
Mikado method
A change
Now the change is easy to implement
![Page 33: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/33.jpg)
Benefits of such approach
Codebase every time is in good state
You won’t have such situation that time is go on and everything is broken
You always keep focus on target
![Page 34: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/34.jpg)
Refactoring strategies
Big Bang - Define the structure for the final state and push code to its ultimate home
Divide and conquer - Try to separate the big ball of mud into two pieces. Repeat until
done...
Strangling
![Page 35: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/35.jpg)
Why people like big bang?
Strangling is very expensive, It’s cute but not for us
We don’t have tight schedule for this refactoring, let’s safely make a changes in branch
We have to do a lot of changes we can’t divide problem into pieces
It’s a risky
![Page 36: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/36.jpg)
Why do we need to refactor code ?
Did you face with such term as “Risky change” ?
![Page 37: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/37.jpg)
What information is hidden?
From practical standpoint big bang never happens
successfully
![Page 38: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/38.jpg)
Why do we change
code?
Why to refactor
workable code?
Refactoring strategies
Case study
Summary
Agenda
![Page 39: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/39.jpg)
Case study
What refactor strategy should be used ?
Big Bang - Define the structure for the final state and push code to its ultimate home
Divide and conquer - Try to separate the big ball of mud into two pieces. Repeat until
done...
Strangling
![Page 40: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/40.jpg)
We used mixed
Divide and conquer - Try to separate the big ball of mud into two pieces. Repeat until
done...
Strangling
![Page 41: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/41.jpg)
Refactoring taxonomy
• Guarantee that we have reliable mechanism to check that everything works
• Create infrastructure to switch implementations
• Utilize dependency injection
• Finish refactoring (divide and conquer)
![Page 42: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/42.jpg)
Guarantee that we have reliable mechanism to check that everything works
• Unit tests: create necessary coverage and verifications for authentication/authorization flows
• Initiated integration tests
• UI automation tests check that everything is verified
• Don’t forget about concurrent scenarios
![Page 43: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/43.jpg)
Create infrastructure: gather old structure
Application
Security Old code structure
Session context
![Page 44: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/44.jpg)
Create infrastructure: Create new structure
Application
Security Old Security New Adapter
35% of deal
![Page 45: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/45.jpg)
Utilize Dependency Injection
Switch (web.xml)
Security Old (application context)
Security New (application context
Adapter APIInterfaces only
Security New classes (implemented in v2 package)
Spring managed context
Security Old classes(Current implementation)
Servlet session context
Application Code
Old Application boundaries
New application boundaries
Adapter classes
![Page 46: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/46.jpg)
Finish refactoring: make new Security workable
Switch (web.xml)
Security New (application context
Adapter APIInterfaces only
Security New classes (implemented in v2 package)
Spring managed context
Application Code
New application boundaries
![Page 47: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/47.jpg)
Finish refactoring drop old code
Switch (web.xml)
Security Old (application context)
Adapter APIInterfaces only
Security Old classes(Current implementation)
Servlet session context
Application Code
Old Application boundaries
Adapter classes
![Page 48: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/48.jpg)
Summary
• Please don’t believe in risk• Write code that doesn’t require further
refactoring• In case you need to refactor a large project
please think 10 times before doing this.
![Page 49: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/49.jpg)
Write code to have your house in good state
![Page 50: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/50.jpg)
Useful Links
• Refactoring Large Software Systems• Michael C. Feathers Working efficiently
with legacy code • Refactoring legacy applications• Large scale refactoring
![Page 51: large scale Refactoring](https://reader035.fdocuments.net/reader035/viewer/2022062310/568162f8550346895dd37107/html5/thumbnails/51.jpg)
Questions