SlideShare ist ein Scribd-Unternehmen logo
1 von 49
Downloaden Sie, um offline zu lesen
TOOL-DRIVEN RESTRUCTURING OF
LARGE CODEBASES
ganesh samarthyam
(ganesh@codeops.tech)
FOCUS ON REPAYING ARCHITECTURE DEBT HERE


Code debt
Static
analysis tool
violations
Coding style
violations
Design debt
Design smells
Violations of
design rules
Test debt
Lack of tests
Inadequate
test coverage
Architecture debt
Lacking
structure (esp.
tangles)
Violation of
architecture
constraints
our focus is mainly here

UNDERLYING PRINCIPLES
‱ First: Prefer non-invasive
architecture restructuring
instead of invasive code
changes
‱ Second: “Automation” –
rely on combination of tools
for automated improvement
‱ Third: “Assure” – prefactor
to practice and show its
safe and gives great
beneïŹts
LARGE (LEGACY) CODE
➀ Positives:
➀ Working code
➀ Tried and tested
➀ Stable & known
➀ 

➀ Negatives:
➀ “Touch here breaks there” (lack of visibility &
deteriorating structure)
➀ No ONE knows how it works (but we do know
it works!)
➀ Limited resources (unclear investment beneïŹts)
➀ 

CORE ISSUE: DIFFICULT TO UNDERSTAND & LACKS STRUCTURE
➀ Lack of shared understanding of the whole system
➀ Original developers have long left the team
➀ New developers take a long time to become productive
➀ Structure has deteriorated over time (existing structure works
against development)
➀ Accidental changes to the structure (on need basis) than
intentional changes that preserves structure
➀ Changing code is “perceived risky” - hard to predict impact
➀ As developers we don’t know how to ïŹx the code or add
features; when we know, can’t be sure if it won’t break
anything (lack of automated unit tests adds to the problem)
Source: Consortium of IT Software Quality (CISQ), Bill Curtis, Architecturally Complex Defects, 2012
WHICH ONE WOULD YOU LIKE TO WORK ON?
V 0.7.2
V 1.3.5
https://sourceforge.net/projects/ïŹndbugs/ïŹles/ïŹndbugs/
STARTS WITH AN UNDERSTANDABLE INTENSIONAL STRUCTURE
V 0.7.2
GETS SLIGHTLY COMPLICATED
V 0.8.6
FIRST TANGLE APPEARS
V 0.8.7
AND THE TANGLE SPREADS
V 0.8.8
ITS GETTING TOUGHER TO DEAL WITH
V 1.0.0
IT IS GETTING WORSER
V 1.3.0
ITS A MESS NOW!
V 1.3.5
HOW DO WE DEAL WITH THIS SITUATION?
DOES MODULARITY MATTER?
Tangles in
JDK
“MODULARIZED” SOLUTION (JDK 9)
MODULARITY IS THE KEY: REMOVING TANGLES AND FAT
➀ Tangles - entities are directly or indirectly depending on each
other (classes, packages, etc)
➀ Fat - excessive complexity of an entity (methods, classes,
packages etc)
ARE YOU IN THIS SITUATION? => DO THIS!
ARE YOU IN THIS SITUATION? => DO THIS!
UNDERSTANDING PHYSICAL/CLASS TANGLES
Step 1: Separate the interface & implementation
Step 2: Depend on the interfaces (and not on the implementations)
(Reflection: Needs code-level changes)
UNDERSTANDING PACKAGE-LEVEL TANGLES
Step 1: Create a separate package for the interface(s)
Step 2: Separate the interface & implementation
(Reflection: Needs package-moves - no code level changes)
HOW TO EXTRACT A MODULE FROM A TANGLE?
HOW TO EXTRACT A MODULE FROM A TANGLE?
SEPARATE INTERFACE & IMPL - FOR ‘CLASSREALM’ (WITHOUT CYCLE)
Step: Separate the interfaces in “maven-classrealm” from the
implementation (concrete classes) into to a separate module
(“maven-classrealm-api”)
(Reflection: NO CODE CHANGE(S) NEEDED!!)
STORY OF HOW BUILD TOOL GOT EXTRACTED
Smell Detector tool
(UI &
implementation
logic)
Request came in
for build-time
checking tool
Smell Detector Tool
(UI)
Smell Detector
Build Tool
(headless)
Smell Detector
Implementation
Logic (DLL)
Interface
WHAT IS “PRESTRUCTURING”?
WHAT IS PRESTRUCTURING?
➀ Jack is “chained” – aka “tangled” ;-)
➀ Rose is scared to use axe because too risky and lacks experience –
aka “fear of breaking the working code” - hence practices ïŹrst!
➀ “Rehearse restructuring the codebase without actually making the
code changes!”
➀ Safely try out the speciïŹc structural changes
➀ Evaluate beneïŹts & trade-oïŹ€s
➀ Undo if needed
➀ Discuss and brainstorm by “trying out things”
➀ Plan the actual restructuring
➀ To the speciïŹc / exact steps and details
REFACTORING VS. RESTRUCTURING
Code Refactoring Modular Restructuring
It is improving the underlying design of
existing code through code modiïŹcations to
improve quality of the software, esp.
maintainability.
Improving the structure of the code-base with
little or no modiïŹcations to the existing code to
improve software modularity.
Target of change: Code itself. Refactoring is
done directly to the code (physical level).
Target of change: Code base. Changes are
done largely at higher levels of abstractions
(logical level).
Extent of code changes: A lot of invasive
code editing.
No code editing in most scenarios; sometimes
minimal code editing is needed for speciïŹc
structural issues.
What to refactor: Smells (A code smell is a
surface indication that usually corresponds
to a deeper problem in the system).
What to restructure: Structural issues
(dependencies, levelization, placement, size,
grouping, etc.).
Small worlds of a few classes at a time; what
you see in the IDE (examples: data classes,
large methods, long parameter lists)
Whole codebase; what you don’t see in the
IDE (examples: tangles and cycles, orphan
packages, misplaced class in a package)
BENEFITS - MODULAR RESTRUCTURING
Developer Productivity
(quickening mental
models when working
with code)
The time to understand the
structure of a large codebase
(especially for teams who have
been transferred responsibility
of an existing product) is
drastically reduced
The cost of transfer of
maintenance is lesser as
KT time reduced as much
as 75%
Developer Productivity
(modularization results in
reduced change impact)
The time to make a change
(new enhancement/bug fix) is
drastically reduced as the time
to do impact analysis is
drastically reduced
The bug density is lower
as developers can better
modularize and make
changes confidently
Developer Productivity
(improved build times)
Modularization results in
reduced time for compilation &
more modular components as
part of a modular build system
Faster build times (even
upto 90%) resulting in
quicker turnaround time
for developers for
changes + quicker unit
testing
CATALOG OF RESTRUCTURINGS
“FATTY PACKAGE” – TOO MANY CLASSES IN A PACKAGE
Potential cause
Missing packaging of classes
Restructuring
Step 1: Auto-group and levelized
Step 2: Identify technical or functional groups
Step 3: Wrap them into sub-packages
“MISSING PACKAGING”
When there are few / no tangles in a package and there are many classes, it
indicates that subpackaging is missing
Pulling from bottom or top as packaging exposes new opportunities for subpackaging
So perform restructuring iteratively (not in one go)
“MISPLACED CLASS(ES)”
Restructuring
Move it to the suitable container 
“TROUBLEMAKER CLASS”
Structural issue: A class should logically belong to the current package but causes cyclic dependency if
left as it is!
Potential cause: Implementation code (perhaps inadvertently) results in a cycle; 
Restructuring:  
Option 1: Refactor the implementation code (not recommended in this case)
Option 2: Move it outside the package (simple and effective solution in this case)
“MISPLACED-TROUBLEMAKER CLASS!”
Structural issue: A class should logically belong to the suitable package but causes cyclic dependency if
moved to that package
Potential cause: Implementation code (perhaps inadvertently) results in a cycle
Restructuring:  
Option 1: Refactor the implementation code (not recommended in this case)
Option 2: Move it outside the package (simple and effective solution in this case)
“ORPHANS”
Structural issue
Unreferenced entities in the code base
Potential causes
Historic nature – used earlier but not
anymore
Left-overs – created but never used
Caution
It may be actually used but does not
have dependencies visible at compiled-
code level
Through features like reïŹ‚ection or as APIs
Or using mechanisms external to the language
Restructuring 
Step 1: Determine that they are actually
unused
Step 2: Remove them
Your chance to commit “pre-mediated
murders of innocent orphans” and
become a “killer coder” ;-)
“KNOTTY PACKAGES”
Structural issue
Packages are too much tangled 
Potential cause
Haphazard organization without
thinking
Degradation over time 
Restructuring – “unwrap and
regroup”
Step 1: Unwrap packages
Step 2: Regroup classes (“Auto-
regroup”)
Step 3: Wrap into proper packages
(“Realize”)
Tool hint: Try “auto-levelization”
magic!
“KNOTTY CLASSES”
Structural issue
Classes within a package are too much tangled 
Potential cause
Lack of grouping/sub-packaging
Restructuring 
Step 1: Autogroup classes
Step 2: Wrap relevant groups into sub-packages (“Realize”)
“UNTIDY PACKAGE”
Structural issue
Both fat and tangles in the package
Potential cause
Haphazard organization (putting things in a package without thinking about structure)
Restructuring 
Step 1: Unwrap everything the package to class level
Step 2: Identify groups / cohesive clusters
Step 3: Repackage with new packages
MAKING “PRAGMATIC CHOICES” IN RESTRUCTURING
ThreadLocalUtility causes tangles
“Used by”: “async” and “webapp”
“Uses”: “async”, “context”, and “webapp” 
Going by the names of the entities “thread-local-utility” best belongs to “async” but
move it to “webapp”
But if we move it there, it will cause tangle between “async” and “webapp”
Perfectionist approach will move it to “async” and also do “code refactoring” to get rid of the tangle – why should
ThreadLocalUtility depend on “webapp” or “context”?
Arguably pragmatic approach: Move it to “webapp” because it will resolve tangle though it doesn’t belong there
FUNDAMENTAL MODULARISATION PRICIPLES
Modularization
Levelization /
Layering
Grouping Chunking
Encapsulation /
hiding
Ordering
“Prefer “a move” (code restructuring)
instead of “invasive code
change” (code refactoring)
A BIG IDEA!
TOOLS FOR REFACTORING & RESTRUCTURING
➀ CodeScene
➀ Designite
➀ JArchitect / NDepend / CppDepend
➀ Lattix
➀ ReSharper
➀ Sotograph / SotoArc
➀ and more 

BIG IDEAS AND TAKEAWAYS
➀ It is possible to modularize WITHOUT changing
any code!
➀ Prefer making non-invasive architecture
restructuring (e.g., class moves to remove a
package tangle) instead of making invasive code
changes (e.g., change the code inside a class to
remove the oïŹ€ending dependency)
➀ Tools are your friends - befriend them :-)
APPLYING PRINCIPLES
CREDITS
➀ For the FindBugs example: Structure101 team
➀ For applying principles image: our book “Refactoring for
Software Design Smells”
➀ Module system in JDK 9 - blogs.oracle.com
➀ Modular restructuring beneïŹts: Manoj Ganapathi (CodeOps)
➀ For the “maven class-realm” module extraction case study:
Mike Swainston-Rainford
➀ Source for the quotation: Consortium of IT Software Quality
(CISQ), Bill Curtis, Architecturally Complex Defects, 2012
IMAGE CREDITS
➀ https://pixabay.com/illustrations/lion-image-editing-graphic-
program-66898/
➀ https://pixabay.com/photos/roofs-houses-historic-center-
italy-919460/
www.codeops.tech
www.konfhub.com
www.designsmells.com
ganesh@codeops.tech
bit.ly/ganeshsg
@GSamarthyam

Weitere Àhnliche Inhalte

Ähnlich wie Tool Driven Restructuring of Large Codebases

Bridging the Divide between Architecture and Code (Germany JUGs version)
Bridging the Divide between Architecture and Code (Germany JUGs version)Bridging the Divide between Architecture and Code (Germany JUGs version)
Bridging the Divide between Architecture and Code (Germany JUGs version)
Chris Chedgey
 
Linq 1224887336792847 9
Linq 1224887336792847 9Linq 1224887336792847 9
Linq 1224887336792847 9
google
 
Object oriented basics
Object oriented basicsObject oriented basics
Object oriented basics
vamshimahi
 
Just In Time Scalability Agile Methods To Support Massive Growth Presentation
Just In Time Scalability  Agile Methods To Support Massive Growth PresentationJust In Time Scalability  Agile Methods To Support Massive Growth Presentation
Just In Time Scalability Agile Methods To Support Massive Growth Presentation
Eric Ries
 
Kelly potvin nosurprises_odtug_oow12
Kelly potvin nosurprises_odtug_oow12Kelly potvin nosurprises_odtug_oow12
Kelly potvin nosurprises_odtug_oow12
Enkitec
 
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
Mike Harris
 

Ähnlich wie Tool Driven Restructuring of Large Codebases (20)

Bridging the Divide between Architecture and Code (Germany JUGs version)
Bridging the Divide between Architecture and Code (Germany JUGs version)Bridging the Divide between Architecture and Code (Germany JUGs version)
Bridging the Divide between Architecture and Code (Germany JUGs version)
 
Writing Quality Code
Writing Quality CodeWriting Quality Code
Writing Quality Code
 
Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design pattern
 
Refactoring: Improve the design of existing code
Refactoring: Improve the design of existing codeRefactoring: Improve the design of existing code
Refactoring: Improve the design of existing code
 
Few minutes To better Code - Refactoring
Few minutes To better Code - RefactoringFew minutes To better Code - Refactoring
Few minutes To better Code - Refactoring
 
Clean code-v2.2
Clean code-v2.2Clean code-v2.2
Clean code-v2.2
 
Refactoring_Rosenheim_2008_Workshop
Refactoring_Rosenheim_2008_WorkshopRefactoring_Rosenheim_2008_Workshop
Refactoring_Rosenheim_2008_Workshop
 
Devry CIS 247 Full Course Latest
Devry CIS 247 Full Course LatestDevry CIS 247 Full Course Latest
Devry CIS 247 Full Course Latest
 
Linq 1224887336792847 9
Linq 1224887336792847 9Linq 1224887336792847 9
Linq 1224887336792847 9
 
Abap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorialsAbap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorials
 
5 transition to design
5 transition to design5 transition to design
5 transition to design
 
Week4 grasp-into
Week4 grasp-intoWeek4 grasp-into
Week4 grasp-into
 
Object oriented basics
Object oriented basicsObject oriented basics
Object oriented basics
 
Just In Time Scalability Agile Methods To Support Massive Growth Presentation
Just In Time Scalability  Agile Methods To Support Massive Growth PresentationJust In Time Scalability  Agile Methods To Support Massive Growth Presentation
Just In Time Scalability Agile Methods To Support Massive Growth Presentation
 
Just In Time Scalability Agile Methods To Support Massive Growth Presentation
Just In Time Scalability  Agile Methods To Support Massive Growth PresentationJust In Time Scalability  Agile Methods To Support Massive Growth Presentation
Just In Time Scalability Agile Methods To Support Massive Growth Presentation
 
Software Patterns
Software PatternsSoftware Patterns
Software Patterns
 
Workshop - The Little Pattern That Could.pdf
Workshop - The Little Pattern That Could.pdfWorkshop - The Little Pattern That Could.pdf
Workshop - The Little Pattern That Could.pdf
 
Code review
Code reviewCode review
Code review
 
Kelly potvin nosurprises_odtug_oow12
Kelly potvin nosurprises_odtug_oow12Kelly potvin nosurprises_odtug_oow12
Kelly potvin nosurprises_odtug_oow12
 
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
 

Mehr von CodeOps Technologies LLP

Mehr von CodeOps Technologies LLP (20)

AWS Serverless Event-driven Architecture - in lastminute.com meetup
AWS Serverless Event-driven Architecture - in lastminute.com meetupAWS Serverless Event-driven Architecture - in lastminute.com meetup
AWS Serverless Event-driven Architecture - in lastminute.com meetup
 
Understanding azure batch service
Understanding azure batch serviceUnderstanding azure batch service
Understanding azure batch service
 
DEVOPS AND MACHINE LEARNING
DEVOPS AND MACHINE LEARNINGDEVOPS AND MACHINE LEARNING
DEVOPS AND MACHINE LEARNING
 
SERVERLESS MIDDLEWARE IN AZURE FUNCTIONS
SERVERLESS MIDDLEWARE IN AZURE FUNCTIONSSERVERLESS MIDDLEWARE IN AZURE FUNCTIONS
SERVERLESS MIDDLEWARE IN AZURE FUNCTIONS
 
BUILDING SERVERLESS SOLUTIONS WITH AZURE FUNCTIONS
BUILDING SERVERLESS SOLUTIONS WITH AZURE FUNCTIONSBUILDING SERVERLESS SOLUTIONS WITH AZURE FUNCTIONS
BUILDING SERVERLESS SOLUTIONS WITH AZURE FUNCTIONS
 
APPLYING DEVOPS STRATEGIES ON SCALE USING AZURE DEVOPS SERVICES
APPLYING DEVOPS STRATEGIES ON SCALE USING AZURE DEVOPS SERVICESAPPLYING DEVOPS STRATEGIES ON SCALE USING AZURE DEVOPS SERVICES
APPLYING DEVOPS STRATEGIES ON SCALE USING AZURE DEVOPS SERVICES
 
BUILD, TEST & DEPLOY .NET CORE APPS IN AZURE DEVOPS
BUILD, TEST & DEPLOY .NET CORE APPS IN AZURE DEVOPSBUILD, TEST & DEPLOY .NET CORE APPS IN AZURE DEVOPS
BUILD, TEST & DEPLOY .NET CORE APPS IN AZURE DEVOPS
 
CREATE RELIABLE AND LOW-CODE APPLICATION IN SERVERLESS MANNER
CREATE RELIABLE AND LOW-CODE APPLICATION IN SERVERLESS MANNERCREATE RELIABLE AND LOW-CODE APPLICATION IN SERVERLESS MANNER
CREATE RELIABLE AND LOW-CODE APPLICATION IN SERVERLESS MANNER
 
CREATING REAL TIME DASHBOARD WITH BLAZOR, AZURE FUNCTION COSMOS DB AN AZURE S...
CREATING REAL TIME DASHBOARD WITH BLAZOR, AZURE FUNCTION COSMOS DB AN AZURE S...CREATING REAL TIME DASHBOARD WITH BLAZOR, AZURE FUNCTION COSMOS DB AN AZURE S...
CREATING REAL TIME DASHBOARD WITH BLAZOR, AZURE FUNCTION COSMOS DB AN AZURE S...
 
WRITE SCALABLE COMMUNICATION APPLICATION WITH POWER OF SERVERLESS
WRITE SCALABLE COMMUNICATION APPLICATION WITH POWER OF SERVERLESSWRITE SCALABLE COMMUNICATION APPLICATION WITH POWER OF SERVERLESS
WRITE SCALABLE COMMUNICATION APPLICATION WITH POWER OF SERVERLESS
 
Training And Serving ML Model Using Kubeflow by Jayesh Sharma
Training And Serving ML Model Using Kubeflow by Jayesh SharmaTraining And Serving ML Model Using Kubeflow by Jayesh Sharma
Training And Serving ML Model Using Kubeflow by Jayesh Sharma
 
Deploy Microservices To Kubernetes Without Secrets by Reenu Saluja
Deploy Microservices To Kubernetes Without Secrets by Reenu SalujaDeploy Microservices To Kubernetes Without Secrets by Reenu Saluja
Deploy Microservices To Kubernetes Without Secrets by Reenu Saluja
 
Leverage Azure Tech stack for any Kubernetes cluster via Azure Arc by Saiyam ...
Leverage Azure Tech stack for any Kubernetes cluster via Azure Arc by Saiyam ...Leverage Azure Tech stack for any Kubernetes cluster via Azure Arc by Saiyam ...
Leverage Azure Tech stack for any Kubernetes cluster via Azure Arc by Saiyam ...
 
YAML Tips For Kubernetes by Neependra Khare
YAML Tips For Kubernetes by Neependra KhareYAML Tips For Kubernetes by Neependra Khare
YAML Tips For Kubernetes by Neependra Khare
 
Must Know Azure Kubernetes Best Practices And Features For Better Resiliency ...
Must Know Azure Kubernetes Best Practices And Features For Better Resiliency ...Must Know Azure Kubernetes Best Practices And Features For Better Resiliency ...
Must Know Azure Kubernetes Best Practices And Features For Better Resiliency ...
 
Monitor Azure Kubernetes Cluster With Prometheus by Mamta Jha
Monitor Azure Kubernetes Cluster With Prometheus by Mamta JhaMonitor Azure Kubernetes Cluster With Prometheus by Mamta Jha
Monitor Azure Kubernetes Cluster With Prometheus by Mamta Jha
 
Jet brains space intro presentation
Jet brains space intro presentationJet brains space intro presentation
Jet brains space intro presentation
 
Functional Programming in Java 8 - Lambdas and Streams
Functional Programming in Java 8 - Lambdas and StreamsFunctional Programming in Java 8 - Lambdas and Streams
Functional Programming in Java 8 - Lambdas and Streams
 
Distributed Tracing: New DevOps Foundation
Distributed Tracing: New DevOps FoundationDistributed Tracing: New DevOps Foundation
Distributed Tracing: New DevOps Foundation
 
"Distributed Tracing: New DevOps Foundation" by Jayesh Ahire
"Distributed Tracing: New DevOps Foundation" by Jayesh Ahire  "Distributed Tracing: New DevOps Foundation" by Jayesh Ahire
"Distributed Tracing: New DevOps Foundation" by Jayesh Ahire
 

KĂŒrzlich hochgeladen

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 

KĂŒrzlich hochgeladen (20)

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 

Tool Driven Restructuring of Large Codebases

  • 1. TOOL-DRIVEN RESTRUCTURING OF LARGE CODEBASES ganesh samarthyam (ganesh@codeops.tech)
  • 2. FOCUS ON REPAYING ARCHITECTURE DEBT HERE 
 Code debt Static analysis tool violations Coding style violations Design debt Design smells Violations of design rules Test debt Lack of tests Inadequate test coverage Architecture debt Lacking structure (esp. tangles) Violation of architecture constraints our focus is mainly here

  • 3. UNDERLYING PRINCIPLES ‱ First: Prefer non-invasive architecture restructuring instead of invasive code changes ‱ Second: “Automation” – rely on combination of tools for automated improvement ‱ Third: “Assure” – prefactor to practice and show its safe and gives great beneïŹts
  • 4. LARGE (LEGACY) CODE ➀ Positives: ➀ Working code ➀ Tried and tested ➀ Stable & known ➀ 
 ➀ Negatives: ➀ “Touch here breaks there” (lack of visibility & deteriorating structure) ➀ No ONE knows how it works (but we do know it works!) ➀ Limited resources (unclear investment beneïŹts) ➀ 

  • 5. CORE ISSUE: DIFFICULT TO UNDERSTAND & LACKS STRUCTURE ➀ Lack of shared understanding of the whole system ➀ Original developers have long left the team ➀ New developers take a long time to become productive ➀ Structure has deteriorated over time (existing structure works against development) ➀ Accidental changes to the structure (on need basis) than intentional changes that preserves structure ➀ Changing code is “perceived risky” - hard to predict impact ➀ As developers we don’t know how to ïŹx the code or add features; when we know, can’t be sure if it won’t break anything (lack of automated unit tests adds to the problem)
  • 6. Source: Consortium of IT Software Quality (CISQ), Bill Curtis, Architecturally Complex Defects, 2012
  • 7. WHICH ONE WOULD YOU LIKE TO WORK ON? V 0.7.2 V 1.3.5 https://sourceforge.net/projects/ïŹndbugs/ïŹles/ïŹndbugs/
  • 8. STARTS WITH AN UNDERSTANDABLE INTENSIONAL STRUCTURE V 0.7.2
  • 11. AND THE TANGLE SPREADS V 0.8.8
  • 12. ITS GETTING TOUGHER TO DEAL WITH V 1.0.0
  • 13. IT IS GETTING WORSER V 1.3.0
  • 14. ITS A MESS NOW! V 1.3.5
  • 15. HOW DO WE DEAL WITH THIS SITUATION?
  • 18. MODULARITY IS THE KEY: REMOVING TANGLES AND FAT ➀ Tangles - entities are directly or indirectly depending on each other (classes, packages, etc) ➀ Fat - excessive complexity of an entity (methods, classes, packages etc)
  • 19. ARE YOU IN THIS SITUATION? => DO THIS!
  • 20. ARE YOU IN THIS SITUATION? => DO THIS!
  • 21. UNDERSTANDING PHYSICAL/CLASS TANGLES Step 1: Separate the interface & implementation Step 2: Depend on the interfaces (and not on the implementations) (Reflection: Needs code-level changes)
  • 22. UNDERSTANDING PACKAGE-LEVEL TANGLES Step 1: Create a separate package for the interface(s) Step 2: Separate the interface & implementation (Reflection: Needs package-moves - no code level changes)
  • 23. HOW TO EXTRACT A MODULE FROM A TANGLE?
  • 24. HOW TO EXTRACT A MODULE FROM A TANGLE?
  • 25. SEPARATE INTERFACE & IMPL - FOR ‘CLASSREALM’ (WITHOUT CYCLE) Step: Separate the interfaces in “maven-classrealm” from the implementation (concrete classes) into to a separate module (“maven-classrealm-api”) (Reflection: NO CODE CHANGE(S) NEEDED!!)
  • 26. STORY OF HOW BUILD TOOL GOT EXTRACTED Smell Detector tool (UI & implementation logic) Request came in for build-time checking tool Smell Detector Tool (UI) Smell Detector Build Tool (headless) Smell Detector Implementation Logic (DLL) Interface
  • 28. WHAT IS PRESTRUCTURING? ➀ Jack is “chained” – aka “tangled” ;-) ➀ Rose is scared to use axe because too risky and lacks experience – aka “fear of breaking the working code” - hence practices ïŹrst! ➀ “Rehearse restructuring the codebase without actually making the code changes!” ➀ Safely try out the speciïŹc structural changes ➀ Evaluate beneïŹts & trade-oïŹ€s ➀ Undo if needed ➀ Discuss and brainstorm by “trying out things” ➀ Plan the actual restructuring ➀ To the speciïŹc / exact steps and details
  • 29. REFACTORING VS. RESTRUCTURING Code Refactoring Modular Restructuring It is improving the underlying design of existing code through code modiïŹcations to improve quality of the software, esp. maintainability. Improving the structure of the code-base with little or no modiïŹcations to the existing code to improve software modularity. Target of change: Code itself. Refactoring is done directly to the code (physical level). Target of change: Code base. Changes are done largely at higher levels of abstractions (logical level). Extent of code changes: A lot of invasive code editing. No code editing in most scenarios; sometimes minimal code editing is needed for speciïŹc structural issues. What to refactor: Smells (A code smell is a surface indication that usually corresponds to a deeper problem in the system). What to restructure: Structural issues (dependencies, levelization, placement, size, grouping, etc.). Small worlds of a few classes at a time; what you see in the IDE (examples: data classes, large methods, long parameter lists) Whole codebase; what you don’t see in the IDE (examples: tangles and cycles, orphan packages, misplaced class in a package)
  • 30. BENEFITS - MODULAR RESTRUCTURING Developer Productivity (quickening mental models when working with code) The time to understand the structure of a large codebase (especially for teams who have been transferred responsibility of an existing product) is drastically reduced The cost of transfer of maintenance is lesser as KT time reduced as much as 75% Developer Productivity (modularization results in reduced change impact) The time to make a change (new enhancement/bug fix) is drastically reduced as the time to do impact analysis is drastically reduced The bug density is lower as developers can better modularize and make changes confidently Developer Productivity (improved build times) Modularization results in reduced time for compilation & more modular components as part of a modular build system Faster build times (even upto 90%) resulting in quicker turnaround time for developers for changes + quicker unit testing
  • 32. “FATTY PACKAGE” – TOO MANY CLASSES IN A PACKAGE Potential cause Missing packaging of classes Restructuring Step 1: Auto-group and levelized Step 2: Identify technical or functional groups Step 3: Wrap them into sub-packages
  • 33. “MISSING PACKAGING” When there are few / no tangles in a package and there are many classes, it indicates that subpackaging is missing Pulling from bottom or top as packaging exposes new opportunities for subpackaging So perform restructuring iteratively (not in one go)
  • 35. “TROUBLEMAKER CLASS” Structural issue: A class should logically belong to the current package but causes cyclic dependency if left as it is! Potential cause: Implementation code (perhaps inadvertently) results in a cycle;  Restructuring:   Option 1: Refactor the implementation code (not recommended in this case) Option 2: Move it outside the package (simple and effective solution in this case)
  • 36. “MISPLACED-TROUBLEMAKER CLASS!” Structural issue: A class should logically belong to the suitable package but causes cyclic dependency if moved to that package Potential cause: Implementation code (perhaps inadvertently) results in a cycle Restructuring:   Option 1: Refactor the implementation code (not recommended in this case) Option 2: Move it outside the package (simple and effective solution in this case)
  • 37. “ORPHANS” Structural issue Unreferenced entities in the code base Potential causes Historic nature – used earlier but not anymore Left-overs – created but never used Caution It may be actually used but does not have dependencies visible at compiled- code level Through features like reïŹ‚ection or as APIs Or using mechanisms external to the language Restructuring  Step 1: Determine that they are actually unused Step 2: Remove them Your chance to commit “pre-mediated murders of innocent orphans” and become a “killer coder” ;-)
  • 38. “KNOTTY PACKAGES” Structural issue Packages are too much tangled  Potential cause Haphazard organization without thinking Degradation over time  Restructuring – “unwrap and regroup” Step 1: Unwrap packages Step 2: Regroup classes (“Auto- regroup”) Step 3: Wrap into proper packages (“Realize”) Tool hint: Try “auto-levelization” magic!
  • 39. “KNOTTY CLASSES” Structural issue Classes within a package are too much tangled  Potential cause Lack of grouping/sub-packaging Restructuring  Step 1: Autogroup classes Step 2: Wrap relevant groups into sub-packages (“Realize”)
  • 40. “UNTIDY PACKAGE” Structural issue Both fat and tangles in the package Potential cause Haphazard organization (putting things in a package without thinking about structure) Restructuring  Step 1: Unwrap everything the package to class level Step 2: Identify groups / cohesive clusters Step 3: Repackage with new packages
  • 41. MAKING “PRAGMATIC CHOICES” IN RESTRUCTURING ThreadLocalUtility causes tangles “Used by”: “async” and “webapp” “Uses”: “async”, “context”, and “webapp”  Going by the names of the entities “thread-local-utility” best belongs to “async” but move it to “webapp” But if we move it there, it will cause tangle between “async” and “webapp” Perfectionist approach will move it to “async” and also do “code refactoring” to get rid of the tangle – why should ThreadLocalUtility depend on “webapp” or “context”? Arguably pragmatic approach: Move it to “webapp” because it will resolve tangle though it doesn’t belong there
  • 42. FUNDAMENTAL MODULARISATION PRICIPLES Modularization Levelization / Layering Grouping Chunking Encapsulation / hiding Ordering
  • 43. “Prefer “a move” (code restructuring) instead of “invasive code change” (code refactoring) A BIG IDEA!
  • 44. TOOLS FOR REFACTORING & RESTRUCTURING ➀ CodeScene ➀ Designite ➀ JArchitect / NDepend / CppDepend ➀ Lattix ➀ ReSharper ➀ Sotograph / SotoArc ➀ and more 

  • 45. BIG IDEAS AND TAKEAWAYS ➀ It is possible to modularize WITHOUT changing any code! ➀ Prefer making non-invasive architecture restructuring (e.g., class moves to remove a package tangle) instead of making invasive code changes (e.g., change the code inside a class to remove the oïŹ€ending dependency) ➀ Tools are your friends - befriend them :-)
  • 47. CREDITS ➀ For the FindBugs example: Structure101 team ➀ For applying principles image: our book “Refactoring for Software Design Smells” ➀ Module system in JDK 9 - blogs.oracle.com ➀ Modular restructuring beneïŹts: Manoj Ganapathi (CodeOps) ➀ For the “maven class-realm” module extraction case study: Mike Swainston-Rainford ➀ Source for the quotation: Consortium of IT Software Quality (CISQ), Bill Curtis, Architecturally Complex Defects, 2012
  • 48. IMAGE CREDITS ➀ https://pixabay.com/illustrations/lion-image-editing-graphic- program-66898/ ➀ https://pixabay.com/photos/roofs-houses-historic-center- italy-919460/