SlideShare una empresa de Scribd logo
1 de 34
Restructuring
Improving the modularity of an existing code-base
                  Chris Chedgey
               www.structure101.com
Structure101.com - People
•   Chris Chedgey, Dunmore East, Ireland
•   Paul Hickey, Toulouse, France
•   Paul O’Reilly, Enniscorthy, Ireland
•   Raghvendra Sahu, Delhi, India
•   + 3 contractors
•   No VC’s, no suits
Structure101.com - Products
•   Restructure101
      •   Fix architecture
•   Structure101
      •   Define it
•   Structure101 Build
      •   Enforce it
•   Java, .NET, C/C++, Actionscript, php, …
•   1,000’s users in 100’s companies
Topics

•   What is “Restructuring”?
•   Motivation
•   Understanding structure
•   Restructuring strategies
•   Examples
•   Keeping it structured
What is restructuring?
Refactoring                           Restructuring
•   “Changing code without            •   “Reorganizing a code-base
    modifying behavior to improve         without modifying the code to
    nonfunctional attributes.”            improve modularity”
•   Code is readable                  •   Code-base is understandable
•   A lot of invasive code editing    •   Minimal invasive code editing
•   Scope: small worlds of a few      •   Scope: whole code base; what
    classes at a time; what you see       you don’t see in the IDE
    in the IDE.
What is structure?

•   Composition
•   Dependencies that roll up through composition
•   Nested “levels”
•   Quality factors
      •   Complexity
      •   Modularity
Why is it important?
•   Determines cost of development
•   Predictable impact
•   Testability
•   Reusability
•   Value of your code base
      •   Asset or liability?
Structural quality: complexity
•   Fat                                  •   Eliminate tangles by putting
                                             everything in one place -
      •   Too much complexity in one         creates fat
          place (method, class,
          package, bundle, …)            •   Eliminate fat by simplistically
•   Tangles                                  partitioning fat items – creates
                                             tangles
      •   Cyclic dependencies
      •   Cumulative Component
          Dependency (CCD, Lakos)        Checked
          goes through the roof          automatically
      •   Acyclic Dependency Principle
          (ADP, Bob Martin) – morning
          after syndrome
Structural quality: modularity
•   High cohesion          •   S/W-eng 101
•   Low coupling           •   We ALL know about
                               modularity!
•   Information hiding
•   Interfaces
                           Checked
•   Clear responsibility
                           by human architect
•   …
Visualizing structure – core features
•   Composition
•   Dependency
•   Flow of dependencies
•   Whole codebase
•   Filtering
•   Summarizing
•   Comprehension
Visualizing structure: approaches

•    Lists and treeview
•    Directed graph
•    Dependency Structure Matrix (DSM)
•    Levelized Structure Map (LSM)
Visualizing structure - list & treeview
•   Good to discover specific
    information
•   No dependency flow,
    manipulation
Visualizing structure: directed graphs
•   Info points: #items + #deps
•   Levelizable – good flow
•   #deps becomes a problem
      •   Indicate fat, not fix

•   Infinite nesting not feasible
•   Local comprehension, not for
    global/manipulation
Visualizing structure: DSM
•   Info points: #items2
•   “Scalable” - can be rendered for
    v large graphs
•   Infinite nesting possible
•   Whole code-base
•   Manipulation possible
•   Grow v large
•   Hard to read, bad for the neck
Visualizing structure - LSM
•   Info points: #items
•   Composition, dependency,
    flow, whole codebase,
    filtering, summarizing
•   Goldilocks – designed
    specifically for restructuring
The modularity wasteland
•   Methods ok
•   Classes ok
•   Handfuls of classes ok
       •   Overlapping “small worlds”
       •   Plenty of guidelines
       •   Smells and refactoring
•   But almost no logical organization
    of classes into higher level
    modules
•   This is not scalable
“But we use Java packages!”
•   ` !!
•   Hierarchical ok
•   Support visibility ok
•   BUT: used like a filesystem, not as an
    embodiment of module hierarchy
        •   Composition only

        •   No consideration of dependencies

        •   Little consideration of visibility

        •   Too easy to change (without rules/tools)

•   Becomes a big tangled mess
Modularity stops at class level?
•   Finite aggregation is not
    scalable
•   Oceans of classes
•   Still need to divide and
    conquer
•   Even more – affects the
    whole team
•   Is it inevitable?
Inevitable?
•   No!
•   Spring:
Restructuring strategies
•   Merge parallel structure      •   Do as much as possible by
                                      moving classes and packages
•   Top-down or bottom-up
    decision                      •   Divide disjoint packages early
•   Tackle complexity before      •   Break up v. fat classes and
    modularity                        packages early
•   Break v large class tangles   •   Disentangle
    early
                                  •   Consider mixed granularity
•   Address tangles top-down
                                  •   …
Merge parallel structures
•   Common to separate interfaces/api
    from implementation
•   Perhaps attempt to increase
    awareness of visibility
•   Obscures module structure esp if
    higher in hierarchy
•   Better to consider module sub-items
    as siblings with visibility
•   Keep both if there is a strong
    need/desire for physical code to be
    separate
•   Use of transformations
Merge parallel structures
Bust v large class tangles early
•   Often there is 1 or a few v.large        •   Can the class tangle be contained
    tangles spanning many packages               within a single package?
       •   Making those packages acyclic            •   At least for now?
           means busting the class tangle
                                                    •   Not if classes span to much of the
•   Does it span multiple higher-level                  layering
    layers?
                                                    •   Not if it represents a significant
       •   Break the feedback dependencies              portion of your code base
           between the layers
                                             •   Can you break the tangle into several
                                                 acyclic subsets of tangles?
                                                    •   Each subset can be contained within
                                                        a single package
                                             •   Each subset can be contained within a
                                                 narrow range of ideal leveling
Do as much as you can by moving
classes/packages first
•   Low effort refactoring
•   Less invasive surgery so less risk of impacting behavior
•   Biggest bang for the buck, unless there are v.large class tangles
•   Option to manage architecture separate from physical code
      •   Map classes to physical components
      •   Can’t be done if model requires invasive class editing
Top-down or bottom-up?
•   Top-down                                     •   A bit of both
      •   Preserves as much of the package              •   Preserve top-level breakout
          hierarchy as possible
                                                              •   May reflect team structure
      •   Team can still find classes
                                                              •   Often reflects initial architecture
      •   Feasible if the target structure is
                                                                     •   Sub-modules were not explicitly
          close to the current                                           designed

•   Bottom-up                                           •   Preserve in regions where there is
                                                            relatively small amount of
      •   Current packaging is of little use                restructuring
      •   Target structure is far from current
      •   Often easiest to implement
Make items only using or used by a tangle
Move only used/using child items
Split disjoint packages
Split fat packages and classes
Move feeback from/top
Move feedback to/bottom
Move tangles together
Tackle complexity before (other)
modularity
•   A structure without tangles is much easier to manipulate
•   A milestone in its own right
•   A code-base that is much easier to understand
•   Many simply focus on keeping (over-)complexity out
•   Good basis for further modularization (coupling, cohesion,
    interfaces, …)
Summary
•   The modularity wasteland is normal
•   It costs
•   It can be salvaged
•   It is not easy, but the returns can be huge
•   Questions?
•   Thank you!

Más contenido relacionado

Similar a Restructuring

Bridging the divide between architecture and code (US version)
Bridging the divide between architecture and code (US version)Bridging the divide between architecture and code (US version)
Bridging the divide between architecture and code (US version)Chris Chedgey
 
Design Pattern lecture 1
Design Pattern lecture 1Design Pattern lecture 1
Design Pattern lecture 1Julie Iskander
 
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
 
ATXPUG Meetup 11/11/14 - Managing complexity in Puppet Code
ATXPUG Meetup 11/11/14 - Managing complexity in Puppet CodeATXPUG Meetup 11/11/14 - Managing complexity in Puppet Code
ATXPUG Meetup 11/11/14 - Managing complexity in Puppet CodeByron Miller
 
Docker in the Enterprise
Docker in the EnterpriseDocker in the Enterprise
Docker in the EnterpriseSaul Caganoff
 
Calling All Modularity Solutions: A Comparative Study from eBay
Calling All Modularity Solutions: A Comparative Study from eBayCalling All Modularity Solutions: A Comparative Study from eBay
Calling All Modularity Solutions: A Comparative Study from eBayTony Ng
 
Solid Principles Of Design (Design Series 01)
Solid Principles Of Design (Design Series 01)Solid Principles Of Design (Design Series 01)
Solid Principles Of Design (Design Series 01)Heartin Jacob
 
Tool Driven Restructuring of Large Codebases
Tool Driven Restructuring of Large CodebasesTool Driven Restructuring of Large Codebases
Tool Driven Restructuring of Large CodebasesCodeOps Technologies LLP
 
Calling all modularity solutions
Calling all modularity solutionsCalling all modularity solutions
Calling all modularity solutionsSangjin Lee
 
Scala in practice
Scala in practiceScala in practice
Scala in practiceTomer Gabel
 
Architecture Principles CodeStock
Architecture Principles CodeStock Architecture Principles CodeStock
Architecture Principles CodeStock Steve Barbour
 
Onion Architecture / Clean Architecture
Onion Architecture / Clean ArchitectureOnion Architecture / Clean Architecture
Onion Architecture / Clean ArchitectureAttila Bertók
 
Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Codersebbe
 
AkhileshD_Presentation_Core_Java_OOPs.pptx
AkhileshD_Presentation_Core_Java_OOPs.pptxAkhileshD_Presentation_Core_Java_OOPs.pptx
AkhileshD_Presentation_Core_Java_OOPs.pptxAkhilesh740777
 
CAP Theorem - Theory, Implications and Practices
CAP Theorem - Theory, Implications and PracticesCAP Theorem - Theory, Implications and Practices
CAP Theorem - Theory, Implications and PracticesYoav Francis
 

Similar a Restructuring (20)

Bridging the divide between architecture and code (US version)
Bridging the divide between architecture and code (US version)Bridging the divide between architecture and code (US version)
Bridging the divide between architecture and code (US version)
 
Design Pattern lecture 1
Design Pattern lecture 1Design Pattern lecture 1
Design Pattern lecture 1
 
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)
 
ATXPUG Meetup 11/11/14 - Managing complexity in Puppet Code
ATXPUG Meetup 11/11/14 - Managing complexity in Puppet CodeATXPUG Meetup 11/11/14 - Managing complexity in Puppet Code
ATXPUG Meetup 11/11/14 - Managing complexity in Puppet Code
 
Docker in the Enterprise
Docker in the EnterpriseDocker in the Enterprise
Docker in the Enterprise
 
Calling All Modularity Solutions: A Comparative Study from eBay
Calling All Modularity Solutions: A Comparative Study from eBayCalling All Modularity Solutions: A Comparative Study from eBay
Calling All Modularity Solutions: A Comparative Study from eBay
 
Solid Principles Of Design (Design Series 01)
Solid Principles Of Design (Design Series 01)Solid Principles Of Design (Design Series 01)
Solid Principles Of Design (Design Series 01)
 
Tool Driven Restructuring of Large Codebases
Tool Driven Restructuring of Large CodebasesTool Driven Restructuring of Large Codebases
Tool Driven Restructuring of Large Codebases
 
2CPP19 - Summation
2CPP19 - Summation2CPP19 - Summation
2CPP19 - Summation
 
Calling all modularity solutions
Calling all modularity solutionsCalling all modularity solutions
Calling all modularity solutions
 
Scala in practice
Scala in practiceScala in practice
Scala in practice
 
Architecture Principles CodeStock
Architecture Principles CodeStock Architecture Principles CodeStock
Architecture Principles CodeStock
 
Onion Architecture / Clean Architecture
Onion Architecture / Clean ArchitectureOnion Architecture / Clean Architecture
Onion Architecture / Clean Architecture
 
Week4 grasp-into
Week4 grasp-intoWeek4 grasp-into
Week4 grasp-into
 
Hpts 2011 flexible_oltp
Hpts 2011 flexible_oltpHpts 2011 flexible_oltp
Hpts 2011 flexible_oltp
 
Shooting at a Moving Target
Shooting at a Moving TargetShooting at a Moving Target
Shooting at a Moving Target
 
Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Code
 
AkhileshD_Presentation_Core_Java_OOPs.pptx
AkhileshD_Presentation_Core_Java_OOPs.pptxAkhileshD_Presentation_Core_Java_OOPs.pptx
AkhileshD_Presentation_Core_Java_OOPs.pptx
 
Solid
SolidSolid
Solid
 
CAP Theorem - Theory, Implications and Practices
CAP Theorem - Theory, Implications and PracticesCAP Theorem - Theory, Implications and Practices
CAP Theorem - Theory, Implications and Practices
 

Más de Java Usergroup Berlin-Brandenburg

Die fabelhafte Welt Java(Script)-getriebener Enterprise-WebApps (mit Ext JS)
Die fabelhafte Welt Java(Script)-getriebener Enterprise-WebApps (mit Ext JS)Die fabelhafte Welt Java(Script)-getriebener Enterprise-WebApps (mit Ext JS)
Die fabelhafte Welt Java(Script)-getriebener Enterprise-WebApps (mit Ext JS)Java Usergroup Berlin-Brandenburg
 
Jbossas7alsplattformmodernerenterprise anwendungen-130604114410-phpapp02
Jbossas7alsplattformmodernerenterprise anwendungen-130604114410-phpapp02Jbossas7alsplattformmodernerenterprise anwendungen-130604114410-phpapp02
Jbossas7alsplattformmodernerenterprise anwendungen-130604114410-phpapp02Java Usergroup Berlin-Brandenburg
 

Más de Java Usergroup Berlin-Brandenburg (19)

Microbenchmarks - Wer nicht weiß, was er misst misst Mist
Microbenchmarks - Wer nicht weiß, was er misst misst MistMicrobenchmarks - Wer nicht weiß, was er misst misst Mist
Microbenchmarks - Wer nicht weiß, was er misst misst Mist
 
Collections.compare(() -> JDK; Apache; Eclipse, Guava...});
Collections.compare(() -> JDK; Apache; Eclipse, Guava...});Collections.compare(() -> JDK; Apache; Eclipse, Guava...});
Collections.compare(() -> JDK; Apache; Eclipse, Guava...});
 
Built To Last - Nachhaltige Software-Entwicklung
Built To Last - Nachhaltige Software-EntwicklungBuilt To Last - Nachhaltige Software-Entwicklung
Built To Last - Nachhaltige Software-Entwicklung
 
Feature Toggles On Steroids
Feature Toggles On SteroidsFeature Toggles On Steroids
Feature Toggles On Steroids
 
Resilience mit Hystrix
Resilience mit HystrixResilience mit Hystrix
Resilience mit Hystrix
 
Analysis of software systems using jQAssistant and Neo4j
Analysis of software systems using jQAssistant and Neo4jAnalysis of software systems using jQAssistant and Neo4j
Analysis of software systems using jQAssistant and Neo4j
 
Get Back in Control of your SQL
Get Back in Control of your SQLGet Back in Control of your SQL
Get Back in Control of your SQL
 
Die fabelhafte Welt Java(Script)-getriebener Enterprise-WebApps (mit Ext JS)
Die fabelhafte Welt Java(Script)-getriebener Enterprise-WebApps (mit Ext JS)Die fabelhafte Welt Java(Script)-getriebener Enterprise-WebApps (mit Ext JS)
Die fabelhafte Welt Java(Script)-getriebener Enterprise-WebApps (mit Ext JS)
 
Selbstvorstellung Steria Mummert Consulting
Selbstvorstellung Steria Mummert ConsultingSelbstvorstellung Steria Mummert Consulting
Selbstvorstellung Steria Mummert Consulting
 
Graphdatenbanken mit Neo4j
Graphdatenbanken mit Neo4jGraphdatenbanken mit Neo4j
Graphdatenbanken mit Neo4j
 
Jbosseapclustering 130605100557-phpapp02
Jbosseapclustering 130605100557-phpapp02Jbosseapclustering 130605100557-phpapp02
Jbosseapclustering 130605100557-phpapp02
 
Jbossas7alsplattformmodernerenterprise anwendungen-130604114410-phpapp02
Jbossas7alsplattformmodernerenterprise anwendungen-130604114410-phpapp02Jbossas7alsplattformmodernerenterprise anwendungen-130604114410-phpapp02
Jbossas7alsplattformmodernerenterprise anwendungen-130604114410-phpapp02
 
How long can you afford to Stop The World?
How long can you afford to Stop The World?How long can you afford to Stop The World?
How long can you afford to Stop The World?
 
JavaOne Update zur Java Plattform
JavaOne Update zur Java PlattformJavaOne Update zur Java Plattform
JavaOne Update zur Java Plattform
 
Java EE 7 - Overview and Status
Java EE 7  - Overview and StatusJava EE 7  - Overview and Status
Java EE 7 - Overview and Status
 
Fighting Layout Bugs
Fighting Layout BugsFighting Layout Bugs
Fighting Layout Bugs
 
Die Java Plattform Strategie
Die Java Plattform StrategieDie Java Plattform Strategie
Die Java Plattform Strategie
 
Continuous Delivery
Continuous DeliveryContinuous Delivery
Continuous Delivery
 
Continuous Delivery in der Praxis
Continuous Delivery in der PraxisContinuous Delivery in der Praxis
Continuous Delivery in der Praxis
 

Último

Teekay Tankers Q1-24 Earnings Presentation
Teekay Tankers Q1-24 Earnings PresentationTeekay Tankers Q1-24 Earnings Presentation
Teekay Tankers Q1-24 Earnings PresentationTeekay Tankers Ltd
 
Nicola Mining Inc. Corporate Presentation May 2024
Nicola Mining Inc. Corporate Presentation May 2024Nicola Mining Inc. Corporate Presentation May 2024
Nicola Mining Inc. Corporate Presentation May 2024nicola_mining
 
Osisko Development - Investor Presentation - May 2024
Osisko Development - Investor Presentation - May 2024Osisko Development - Investor Presentation - May 2024
Osisko Development - Investor Presentation - May 2024Philip Rabenok
 
Camil Institutional Presentation_Mai24.pdf
Camil Institutional Presentation_Mai24.pdfCamil Institutional Presentation_Mai24.pdf
Camil Institutional Presentation_Mai24.pdfCAMILRI
 
countries with the highest gold reserves in 2024
countries with the highest gold reserves in 2024countries with the highest gold reserves in 2024
countries with the highest gold reserves in 2024Kweku Zurek
 
Financial Results for the Fiscal Year Ended March 2024
Financial Results for the Fiscal Year Ended March 2024Financial Results for the Fiscal Year Ended March 2024
Financial Results for the Fiscal Year Ended March 2024KDDI
 
Western Copper and Gold - May 2024 Presentation
Western Copper and Gold - May 2024 PresentationWestern Copper and Gold - May 2024 Presentation
Western Copper and Gold - May 2024 PresentationPaul West-Sells
 
Collective Mining | Corporate Presentation - May 2024
Collective Mining | Corporate Presentation - May 2024Collective Mining | Corporate Presentation - May 2024
Collective Mining | Corporate Presentation - May 2024CollectiveMining1
 
Corporate Presentation Probe Canaccord Conference 2024.pdf
Corporate Presentation Probe Canaccord Conference 2024.pdfCorporate Presentation Probe Canaccord Conference 2024.pdf
Corporate Presentation Probe Canaccord Conference 2024.pdfProbe Gold
 
Diligence Checklist for Early Stage Startups
Diligence Checklist for Early Stage StartupsDiligence Checklist for Early Stage Startups
Diligence Checklist for Early Stage StartupsTILDEN
 
Camil Institutional Presentation_Mai24.pdf
Camil Institutional Presentation_Mai24.pdfCamil Institutional Presentation_Mai24.pdf
Camil Institutional Presentation_Mai24.pdfCAMILRI
 
Teck Supplemental Information, May 2, 2024
Teck Supplemental Information, May 2, 2024Teck Supplemental Information, May 2, 2024
Teck Supplemental Information, May 2, 2024TeckResourcesLtd
 
Teekay Corporation Q1-24 Earnings Results
Teekay Corporation Q1-24 Earnings ResultsTeekay Corporation Q1-24 Earnings Results
Teekay Corporation Q1-24 Earnings ResultsTeekay Corporation
 
Osisko Gold Royalties Ltd - Corporate Presentation, May 2024
Osisko Gold Royalties Ltd - Corporate Presentation, May 2024Osisko Gold Royalties Ltd - Corporate Presentation, May 2024
Osisko Gold Royalties Ltd - Corporate Presentation, May 2024Osisko Gold Royalties Ltd
 
Terna - 1Q 2024 Consolidated Results Presentation
Terna - 1Q 2024 Consolidated Results PresentationTerna - 1Q 2024 Consolidated Results Presentation
Terna - 1Q 2024 Consolidated Results PresentationTerna SpA
 
AMG Quarterly Investor Presentation May 2024
AMG Quarterly Investor Presentation May 2024AMG Quarterly Investor Presentation May 2024
AMG Quarterly Investor Presentation May 2024gstubel
 
The Leonardo 1Q 2024 Results Presentation
The Leonardo 1Q 2024 Results PresentationThe Leonardo 1Q 2024 Results Presentation
The Leonardo 1Q 2024 Results PresentationLeonardo
 

Último (20)

Teekay Tankers Q1-24 Earnings Presentation
Teekay Tankers Q1-24 Earnings PresentationTeekay Tankers Q1-24 Earnings Presentation
Teekay Tankers Q1-24 Earnings Presentation
 
Nicola Mining Inc. Corporate Presentation May 2024
Nicola Mining Inc. Corporate Presentation May 2024Nicola Mining Inc. Corporate Presentation May 2024
Nicola Mining Inc. Corporate Presentation May 2024
 
Osisko Development - Investor Presentation - May 2024
Osisko Development - Investor Presentation - May 2024Osisko Development - Investor Presentation - May 2024
Osisko Development - Investor Presentation - May 2024
 
Camil Institutional Presentation_Mai24.pdf
Camil Institutional Presentation_Mai24.pdfCamil Institutional Presentation_Mai24.pdf
Camil Institutional Presentation_Mai24.pdf
 
countries with the highest gold reserves in 2024
countries with the highest gold reserves in 2024countries with the highest gold reserves in 2024
countries with the highest gold reserves in 2024
 
Financial Results for the Fiscal Year Ended March 2024
Financial Results for the Fiscal Year Ended March 2024Financial Results for the Fiscal Year Ended March 2024
Financial Results for the Fiscal Year Ended March 2024
 
Western Copper and Gold - May 2024 Presentation
Western Copper and Gold - May 2024 PresentationWestern Copper and Gold - May 2024 Presentation
Western Copper and Gold - May 2024 Presentation
 
Collective Mining | Corporate Presentation - May 2024
Collective Mining | Corporate Presentation - May 2024Collective Mining | Corporate Presentation - May 2024
Collective Mining | Corporate Presentation - May 2024
 
Corporate Presentation Probe Canaccord Conference 2024.pdf
Corporate Presentation Probe Canaccord Conference 2024.pdfCorporate Presentation Probe Canaccord Conference 2024.pdf
Corporate Presentation Probe Canaccord Conference 2024.pdf
 
Diligence Checklist for Early Stage Startups
Diligence Checklist for Early Stage StartupsDiligence Checklist for Early Stage Startups
Diligence Checklist for Early Stage Startups
 
Camil Institutional Presentation_Mai24.pdf
Camil Institutional Presentation_Mai24.pdfCamil Institutional Presentation_Mai24.pdf
Camil Institutional Presentation_Mai24.pdf
 
ITAU EQUITY_STRATEGY_WARM_UP_20240505 DHG.pdf
ITAU EQUITY_STRATEGY_WARM_UP_20240505 DHG.pdfITAU EQUITY_STRATEGY_WARM_UP_20240505 DHG.pdf
ITAU EQUITY_STRATEGY_WARM_UP_20240505 DHG.pdf
 
Teck Supplemental Information, May 2, 2024
Teck Supplemental Information, May 2, 2024Teck Supplemental Information, May 2, 2024
Teck Supplemental Information, May 2, 2024
 
Teekay Corporation Q1-24 Earnings Results
Teekay Corporation Q1-24 Earnings ResultsTeekay Corporation Q1-24 Earnings Results
Teekay Corporation Q1-24 Earnings Results
 
Osisko Gold Royalties Ltd - Corporate Presentation, May 2024
Osisko Gold Royalties Ltd - Corporate Presentation, May 2024Osisko Gold Royalties Ltd - Corporate Presentation, May 2024
Osisko Gold Royalties Ltd - Corporate Presentation, May 2024
 
Terna - 1Q 2024 Consolidated Results Presentation
Terna - 1Q 2024 Consolidated Results PresentationTerna - 1Q 2024 Consolidated Results Presentation
Terna - 1Q 2024 Consolidated Results Presentation
 
AMG Quarterly Investor Presentation May 2024
AMG Quarterly Investor Presentation May 2024AMG Quarterly Investor Presentation May 2024
AMG Quarterly Investor Presentation May 2024
 
The Leonardo 1Q 2024 Results Presentation
The Leonardo 1Q 2024 Results PresentationThe Leonardo 1Q 2024 Results Presentation
The Leonardo 1Q 2024 Results Presentation
 
SME IPO Opportunity and Trends of May 2024
SME IPO Opportunity and Trends of May 2024SME IPO Opportunity and Trends of May 2024
SME IPO Opportunity and Trends of May 2024
 
Osisko Gold Royalties Ltd - Q1 2024 Results
Osisko Gold Royalties Ltd - Q1 2024 ResultsOsisko Gold Royalties Ltd - Q1 2024 Results
Osisko Gold Royalties Ltd - Q1 2024 Results
 

Restructuring

  • 1. Restructuring Improving the modularity of an existing code-base Chris Chedgey www.structure101.com
  • 2. Structure101.com - People • Chris Chedgey, Dunmore East, Ireland • Paul Hickey, Toulouse, France • Paul O’Reilly, Enniscorthy, Ireland • Raghvendra Sahu, Delhi, India • + 3 contractors • No VC’s, no suits
  • 3. Structure101.com - Products • Restructure101 • Fix architecture • Structure101 • Define it • Structure101 Build • Enforce it • Java, .NET, C/C++, Actionscript, php, … • 1,000’s users in 100’s companies
  • 4. Topics • What is “Restructuring”? • Motivation • Understanding structure • Restructuring strategies • Examples • Keeping it structured
  • 5. What is restructuring? Refactoring Restructuring • “Changing code without • “Reorganizing a code-base modifying behavior to improve without modifying the code to nonfunctional attributes.” improve modularity” • Code is readable • Code-base is understandable • A lot of invasive code editing • Minimal invasive code editing • Scope: small worlds of a few • Scope: whole code base; what classes at a time; what you see you don’t see in the IDE in the IDE.
  • 6. What is structure? • Composition • Dependencies that roll up through composition • Nested “levels” • Quality factors • Complexity • Modularity
  • 7. Why is it important? • Determines cost of development • Predictable impact • Testability • Reusability • Value of your code base • Asset or liability?
  • 8. Structural quality: complexity • Fat • Eliminate tangles by putting everything in one place - • Too much complexity in one creates fat place (method, class, package, bundle, …) • Eliminate fat by simplistically • Tangles partitioning fat items – creates tangles • Cyclic dependencies • Cumulative Component Dependency (CCD, Lakos) Checked goes through the roof automatically • Acyclic Dependency Principle (ADP, Bob Martin) – morning after syndrome
  • 9. Structural quality: modularity • High cohesion • S/W-eng 101 • Low coupling • We ALL know about modularity! • Information hiding • Interfaces Checked • Clear responsibility by human architect • …
  • 10. Visualizing structure – core features • Composition • Dependency • Flow of dependencies • Whole codebase • Filtering • Summarizing • Comprehension
  • 11. Visualizing structure: approaches • Lists and treeview • Directed graph • Dependency Structure Matrix (DSM) • Levelized Structure Map (LSM)
  • 12. Visualizing structure - list & treeview • Good to discover specific information • No dependency flow, manipulation
  • 13. Visualizing structure: directed graphs • Info points: #items + #deps • Levelizable – good flow • #deps becomes a problem • Indicate fat, not fix • Infinite nesting not feasible • Local comprehension, not for global/manipulation
  • 14. Visualizing structure: DSM • Info points: #items2 • “Scalable” - can be rendered for v large graphs • Infinite nesting possible • Whole code-base • Manipulation possible • Grow v large • Hard to read, bad for the neck
  • 15. Visualizing structure - LSM • Info points: #items • Composition, dependency, flow, whole codebase, filtering, summarizing • Goldilocks – designed specifically for restructuring
  • 16. The modularity wasteland • Methods ok • Classes ok • Handfuls of classes ok • Overlapping “small worlds” • Plenty of guidelines • Smells and refactoring • But almost no logical organization of classes into higher level modules • This is not scalable
  • 17. “But we use Java packages!” • ` !! • Hierarchical ok • Support visibility ok • BUT: used like a filesystem, not as an embodiment of module hierarchy • Composition only • No consideration of dependencies • Little consideration of visibility • Too easy to change (without rules/tools) • Becomes a big tangled mess
  • 18. Modularity stops at class level? • Finite aggregation is not scalable • Oceans of classes • Still need to divide and conquer • Even more – affects the whole team • Is it inevitable?
  • 19. Inevitable? • No! • Spring:
  • 20. Restructuring strategies • Merge parallel structure • Do as much as possible by moving classes and packages • Top-down or bottom-up decision • Divide disjoint packages early • Tackle complexity before • Break up v. fat classes and modularity packages early • Break v large class tangles • Disentangle early • Consider mixed granularity • Address tangles top-down • …
  • 21. Merge parallel structures • Common to separate interfaces/api from implementation • Perhaps attempt to increase awareness of visibility • Obscures module structure esp if higher in hierarchy • Better to consider module sub-items as siblings with visibility • Keep both if there is a strong need/desire for physical code to be separate • Use of transformations
  • 23. Bust v large class tangles early • Often there is 1 or a few v.large • Can the class tangle be contained tangles spanning many packages within a single package? • Making those packages acyclic • At least for now? means busting the class tangle • Not if classes span to much of the • Does it span multiple higher-level layering layers? • Not if it represents a significant • Break the feedback dependencies portion of your code base between the layers • Can you break the tangle into several acyclic subsets of tangles? • Each subset can be contained within a single package • Each subset can be contained within a narrow range of ideal leveling
  • 24. Do as much as you can by moving classes/packages first • Low effort refactoring • Less invasive surgery so less risk of impacting behavior • Biggest bang for the buck, unless there are v.large class tangles • Option to manage architecture separate from physical code • Map classes to physical components • Can’t be done if model requires invasive class editing
  • 25. Top-down or bottom-up? • Top-down • A bit of both • Preserves as much of the package • Preserve top-level breakout hierarchy as possible • May reflect team structure • Team can still find classes • Often reflects initial architecture • Feasible if the target structure is • Sub-modules were not explicitly close to the current designed • Bottom-up • Preserve in regions where there is relatively small amount of • Current packaging is of little use restructuring • Target structure is far from current • Often easiest to implement
  • 26. Make items only using or used by a tangle
  • 27. Move only used/using child items
  • 29. Split fat packages and classes
  • 33. Tackle complexity before (other) modularity • A structure without tangles is much easier to manipulate • A milestone in its own right • A code-base that is much easier to understand • Many simply focus on keeping (over-)complexity out • Good basis for further modularization (coupling, cohesion, interfaces, …)
  • 34. Summary • The modularity wasteland is normal • It costs • It can be salvaged • It is not easy, but the returns can be huge • Questions? • Thank you!

Notas del editor

  1. Guten abendIch bin ein berlinerDarmstadterGood few years agoBit for freedomLast bit of useless info We dev tools – talk not about these – talk after formal pres
  2. 6 components to the company, 4 human, 2 beautifulWe don’t own suitsLove what we doRelentless innovation to solve a big problem
  3. What – relate to refactoringMotivation – modularity/scalabilityUnderstanding – quantifying over complexityRestructuring strategies – emerging from experience, dozens of client engagements and use casesShow parts of products to illustrate principles, not a tutorial on the products
  4. Don’t care whether you use inheritance or aggregationThink of a mass of lines of code, currently organized in one way into methods, classes, packages – we want to reorganize the same lines of code into a different hierarchy of methods, classes, packages.
  5. Can you test a tangle of hundreds of classes?Can’t reuse subsets if everything uses everythingWhen a code-base becomes a liability, sw-engineering has failed
  6. Structural complexity can be assigned thresholds and checked objectively/automatically
  7. We learn about modularity in SW-eng101Builds on complexity principles
  8. Another representation of a graphManipulation involves dragging rows and columns around